Skip to content

Commit abdeee8

Browse files
committed
Added api support for custom token exchange
1 parent 6735a79 commit abdeee8

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
167167
* ```
168168
* client.signinWithPasskey("{authSession}", "{authResponse}","{realm}")
169169
* .validateClaims() //mandatory
170-
* .addParameter("scope","scope")
170+
* .setScope("{scope}")
171171
* .start(object: Callback<Credentials, AuthenticationException> {
172172
* override fun onFailure(error: AuthenticationException) { }
173173
* override fun onSuccess(result: Credentials) { }
@@ -211,7 +211,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
211211
* ```
212212
* client.signinWithPasskey("{authSession}", "{authResponse}","{realm}")
213213
* .validateClaims() //mandatory
214-
* .addParameter("scope","scope")
214+
* .setScope("{scope}")
215215
* .start(object: Callback<Credentials, AuthenticationException> {
216216
* override fun onFailure(error: AuthenticationException) { }
217217
* override fun onSuccess(result: Credentials) { }
@@ -707,6 +707,39 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
707707
.addParameters(parameters)
708708
}
709709

710+
/**
711+
* The Custom Token Exchange feature allows clients to exchange their existing tokens for Auth0 tokens by calling the /oauth/token endpoint with specific parameters
712+
* The default scope used is 'openid profile email'.
713+
*
714+
* Example usage:
715+
*
716+
* ```
717+
* client.callTokenExchange("{subject token type}", "{subject token}")
718+
* .validateClaims() //mandatory
719+
* .setScope("{scope}")
720+
* .setAudience("{audience}")
721+
* .start(object: Callback<Credentials, AuthenticationException> {
722+
* override fun onSuccess(result: Credentials) { }
723+
* override fun onFailure(error: AuthenticationException) { }
724+
* })
725+
* ```
726+
*
727+
* @param subjectTokenType the subject token type that is associated with the existing Identity Provider. e.g. 'http://acme.com/legacy-token'
728+
* @param subjectToken the subject token, typically obtained through the Identity Provider's SDK
729+
* @return a request to configure and start that will yield [Credentials]
730+
*/
731+
public fun callTokenExchange(
732+
subjectTokenType: String,
733+
subjectToken: String,
734+
): AuthenticationRequest {
735+
val parameters = ParameterBuilder.newBuilder()
736+
.setGrantType(ParameterBuilder.GRANT_TYPE_TOKEN_EXCHANGE)
737+
.set(SUBJECT_TOKEN_TYPE_KEY, subjectTokenType)
738+
.set(SUBJECT_TOKEN_KEY, subjectToken)
739+
.asDictionary()
740+
return loginWithToken(parameters)
741+
}
742+
710743
/**
711744
* Requests new Credentials using a valid Refresh Token. The received token will have the same audience and scope as first requested.
712745
*

0 commit comments

Comments
 (0)