@@ -6,7 +6,7 @@ import com.auth0.android.authentication.AuthenticationAPIClient
66import com.auth0.android.authentication.AuthenticationException
77import com.auth0.android.callback.Callback
88import com.auth0.android.result.Credentials
9- import com.auth0.android.result.SessionTransferCredentials
9+ import com.auth0.android.result.SSOCredentials
1010import kotlinx.coroutines.suspendCancellableCoroutine
1111import java.util.*
1212import java.util.concurrent.Executor
@@ -55,22 +55,34 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
5555 }
5656
5757 /* *
58- * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException]
59- * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token,
60- * if a new one is issued.
58+ * Creates a new request to exchange a refresh token for a session transfer token that can be used to perform web single sign-on.
59+ *
60+ * When opening your website on any browser or web view, add the session transfer token to the URL as a query
61+ * parameter. Then your website can redirect the user to Auth0's `/authorize` endpoint, passing along the query
62+ * parameter with the session transfer token. For example,
63+ * `https://example.com/login?session_transfer_token=THE_TOKEN`.
64+ *
65+ * It will fail with [CredentialsManagerException] if the existing refresh_token is null or no longer valid.
66+ * This method will handle saving the refresh_token, if a new one is issued.
6167 */
62- override fun getSessionTransferCredentials (callback : Callback <SessionTransferCredentials , CredentialsManagerException >) {
63- getSessionTransferCredentials (emptyMap(), callback)
68+ override fun getSsoCredentials (callback : Callback <SSOCredentials , CredentialsManagerException >) {
69+ getSsoCredentials (emptyMap(), callback)
6470 }
6571
6672 /* *
67- * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException]
68- * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token,
69- * if a new one is issued.
73+ * Creates a new request to exchange a refresh token for a session transfer token that can be used to perform web single sign-on.
74+ *
75+ * When opening your website on any browser or web view, add the session transfer token to the URL as a query
76+ * parameter. Then your website can redirect the user to Auth0's `/authorize` endpoint, passing along the query
77+ * parameter with the session transfer token. For example,
78+ * `https://example.com/login?session_transfer_token=THE_TOKEN`.
79+ *
80+ * It will fail with [CredentialsManagerException] if the existing refresh_token is null or no longer valid.
81+ * This method will handle saving the refresh_token, if a new one is issued.
7082 */
71- override fun getSessionTransferCredentials (
83+ override fun getSsoCredentials (
7284 parameters : Map <String , String >,
73- callback : Callback <SessionTransferCredentials , CredentialsManagerException >
85+ callback : Callback <SSOCredentials , CredentialsManagerException >
7486 ) {
7587 serialExecutor.execute {
7688 val refreshToken = storage.retrieveString(KEY_REFRESH_TOKEN )
@@ -79,21 +91,18 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
7991 return @execute
8092 }
8193
82- val request = authenticationClient.fetchSessionTransferToken (refreshToken)
94+ val request = authenticationClient.ssoExchange (refreshToken)
8395 try {
8496 if (parameters.isNotEmpty()) {
8597 request.addParameters(parameters)
8698 }
8799 val sessionTransferCredentials = request.execute()
88- saveSessionTransferCredentials (sessionTransferCredentials)
100+ saveSsoCredentials (sessionTransferCredentials)
89101 callback.onSuccess(sessionTransferCredentials)
90102 } catch (error: AuthenticationException ) {
91103 val exception = when {
92- error.isRefreshTokenDeleted ||
93- error.isInvalidRefreshToken -> CredentialsManagerException .Code .RENEW_FAILED
94-
95104 error.isNetworkError -> CredentialsManagerException .Code .NO_NETWORK
96- else -> CredentialsManagerException .Code .API_ERROR
105+ else -> CredentialsManagerException .Code .SSO_EXCHANGE_FAILED
97106 }
98107 callback.onFailure(
99108 CredentialsManagerException (
@@ -106,29 +115,41 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
106115 }
107116
108117 /* *
109- * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException]
110- * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token,
111- * if a new one is issued.
118+ * Creates a new request to exchange a refresh token for a session transfer token that can be used to perform web single sign-on.
119+ *
120+ * When opening your website on any browser or web view, add the session transfer token to the URL as a query
121+ * parameter. Then your website can redirect the user to Auth0's `/authorize` endpoint, passing along the query
122+ * parameter with the session transfer token. For example,
123+ * `https://example.com/login?session_transfer_token=THE_TOKEN`.
124+ *
125+ * It will fail with [CredentialsManagerException] if the existing refresh_token is null or no longer valid.
126+ * This method will handle saving the refresh_token, if a new one is issued.
112127 */
113128 @JvmSynthetic
114129 @Throws(CredentialsManagerException ::class )
115- override suspend fun awaitSessionTransferCredentials (): SessionTransferCredentials {
116- return awaitSessionTransferCredentials (emptyMap())
130+ override suspend fun awaitSsoCredentials (): SSOCredentials {
131+ return awaitSsoCredentials (emptyMap())
117132 }
118133
119134 /* *
120- * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException]
121- * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token,
122- * if a new one is issued.
135+ * Creates a new request to exchange a refresh token for a session transfer token that can be used to perform web single sign-on.
136+ *
137+ * When opening your website on any browser or web view, add the session transfer token to the URL as a query
138+ * parameter. Then your website can redirect the user to Auth0's `/authorize` endpoint, passing along the query
139+ * parameter with the session transfer token. For example,
140+ * `https://example.com/login?session_transfer_token=THE_TOKEN`.
141+ *
142+ * It will fail with [CredentialsManagerException] if the existing refresh_token is null or no longer valid.
143+ * This method will handle saving the refresh_token, if a new one is issued.
123144 */
124145 @JvmSynthetic
125146 @Throws(CredentialsManagerException ::class )
126- override suspend fun awaitSessionTransferCredentials (parameters : Map <String , String >): SessionTransferCredentials {
147+ override suspend fun awaitSsoCredentials (parameters : Map <String , String >): SSOCredentials {
127148 return suspendCancellableCoroutine { continuation ->
128- getSessionTransferCredentials (
149+ getSsoCredentials (
129150 parameters,
130- object : Callback <SessionTransferCredentials , CredentialsManagerException > {
131- override fun onSuccess (result : SessionTransferCredentials ) {
151+ object : Callback <SSOCredentials , CredentialsManagerException > {
152+ override fun onSuccess (result : SSOCredentials ) {
132153 continuation.resume(result)
133154 }
134155
@@ -466,21 +487,21 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
466487 }
467488
468489 /* *
469- * Helper method to store the given [SessionTransferCredentials ] refresh token in the storage.
470- * Method will silently return , if the passed credentials has no refresh token.
490+ * Helper method to store the given [SSOCredentials ] refresh token in the storage.
491+ * Method will silently return if the passed credentials have no refresh token.
471492 *
472- * @param sessionTransferCredentials the credentials to save in the storage.
493+ * @param ssoCredentials the credentials to save in the storage.
473494 */
474495 @VisibleForTesting(otherwise = VisibleForTesting .PRIVATE )
475- internal fun saveSessionTransferCredentials ( sessionTransferCredentials : SessionTransferCredentials ) {
476- storage.store(KEY_ID_TOKEN , sessionTransferCredentials .idToken)
496+ internal fun saveSsoCredentials ( ssoCredentials : SSOCredentials ) {
497+ storage.store(KEY_ID_TOKEN , ssoCredentials .idToken)
477498 val existingRefreshToken = storage.retrieveString(KEY_REFRESH_TOKEN )
478499 // Checking if the existing one needs to be replaced with the new one
479- if (sessionTransferCredentials .refreshToken.isNullOrEmpty())
500+ if (ssoCredentials .refreshToken.isNullOrEmpty())
480501 return // No refresh token to save
481- if (sessionTransferCredentials .refreshToken == existingRefreshToken)
502+ if (ssoCredentials .refreshToken == existingRefreshToken)
482503 return // Same refresh token, no need to save
483- storage.store(KEY_REFRESH_TOKEN , sessionTransferCredentials .refreshToken)
504+ storage.store(KEY_REFRESH_TOKEN , ssoCredentials .refreshToken)
484505 }
485506
486507 @VisibleForTesting(otherwise = VisibleForTesting .PRIVATE )
0 commit comments