Skip to content

Commit

Permalink
Moved the api call part to separate method to keep native login with …
Browse files Browse the repository at this point in the history
…FB and custome token exchnage independent
  • Loading branch information
pmathew92 committed Jan 10, 2025
1 parent ab490b0 commit bbeb0e0
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
* @return a request to configure and start that will yield [Credentials]
*/
public fun loginWithNativeSocialToken(token: String, tokenType: String): AuthenticationRequest {
return customTokenExchange(tokenType, token)
return tokenExchange(tokenType, token)
}

/**
Expand Down Expand Up @@ -726,12 +726,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
subjectTokenType: String,
subjectToken: String,
): AuthenticationRequest {
val parameters = ParameterBuilder.newAuthenticationBuilder()
.setGrantType(ParameterBuilder.GRANT_TYPE_TOKEN_EXCHANGE)
.set(SUBJECT_TOKEN_TYPE_KEY, subjectTokenType)
.set(SUBJECT_TOKEN_KEY, subjectToken)
.asDictionary()
return loginWithToken(parameters)
return tokenExchange(subjectTokenType, subjectToken)
}

/**
Expand Down Expand Up @@ -949,6 +944,21 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
return request
}

/**
* Helper function to make a request to the /oauth/token endpoint with the token exchange grant type.
*/
private fun tokenExchange(
subjectTokenType: String,
subjectToken: String
): AuthenticationRequest {
val parameters = ParameterBuilder.newAuthenticationBuilder()
.setGrantType(ParameterBuilder.GRANT_TYPE_TOKEN_EXCHANGE)
.set(SUBJECT_TOKEN_TYPE_KEY, subjectTokenType)
.set(SUBJECT_TOKEN_KEY, subjectToken)
.asDictionary()
return loginWithToken(parameters)
}

private fun profileRequest(): Request<UserProfile, AuthenticationException> {
val url =
auth0.getDomainUrl().toHttpUrl().newBuilder()
Expand Down

0 comments on commit bbeb0e0

Please sign in to comment.