-
Notifications
You must be signed in to change notification settings - Fork 165
Added Native to Web support #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
EXAMPLES.md
Outdated
|
|
||
| This feature allows you to authenticate a user in a web session using the refresh token obtained from the native session without requiring the user to log in again. | ||
|
|
||
| Call the api to fetch a webSessionTransferToken in exchange for a refresh token. Use the obtained token to authenticate the user by calling the `/authorize` end point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Call the api to fetch a webSessionTransferToken in exchange for a refresh token. Use the obtained token to authenticate the user by calling the `/authorize` end point. | |
| Call the API to fetch a webSessionTransferToken in exchange for a refresh token. Use the obtained token to authenticate the user by calling the `/authorize` end point. |
auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt
Outdated
Show resolved
Hide resolved
auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt
Outdated
Show resolved
Hide resolved
auth0/src/main/java/com/auth0/android/authentication/storage/CredentialsManager.kt
Outdated
Show resolved
Hide resolved
|
|
||
| /** | ||
| * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException] | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | |
| * Fetches a new [SessionTransferCredentials]. It will fail with [CredentialsManagerException] |
| } | ||
|
|
||
| /** | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | |
| * Fetches a new [SessionTransferCredentials]. It will fail with [CredentialsManagerException] |
| * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException] | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | ||
| * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token, | ||
| * if a new one is issued. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * if a new one is issued. | |
| * if a new one is issued. |
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | ||
| * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token, | ||
| * if a new one is issued | ||
| * if a new one is issued. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * if a new one is issued. | |
| * if a new one is issued. |
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | ||
| * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token, | ||
| * if a new one is issued | ||
| * if a new one is issued. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * if a new one is issued. | |
| * if a new one is issued. |
| * @param ssoCredentials the credentials to save in the storage. | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | ||
| * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token, | ||
| * if a new one is issued. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * if a new one is issued. | |
| * if a new one is issued. |
|
|
||
| /** | ||
| * Helper method to store the given [SessionTransferCredentials] refresh token in the storage. | ||
| * Method will silently return ,if the passed credentials has no refresh token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Method will silently return ,if the passed credentials has no refresh token. | |
| * Method will silently return if the passed credentials have no refresh token. |
| * the client. Method will silently return ,if the passed credentials has no refresh token. | ||
| * | ||
| * @param ssoCredentials the credentials to save in the storage. | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | |
| * Fetches a new [SessionTransferCredentials]. It will fail with [CredentialsManagerException] |
| * @param ssoCredentials the credentials to save in the storage. | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | ||
| * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token, | ||
| * if a new one is issued. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * if a new one is issued. | |
| * if a new one is issued. |
|
|
||
| /** | ||
| * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException] | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | |
| * Fetches a new [SessionTransferCredentials]. It will fail with [CredentialsManagerException] |
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | ||
| * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token, | ||
| * if a new one is issued | ||
| * if a new one is issued. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * if a new one is issued. | |
| * if a new one is issued. |
| val exception = when { | ||
| error.isRefreshTokenDeleted || | ||
| error.isInvalidRefreshToken -> CredentialsManagerException.Code.RENEW_FAILED | ||
| error.isRefreshTokenDeleted || error.isInvalidRefreshToken -> CredentialsManagerException.Code.RENEW_FAILED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw a distinct error here?
|
|
||
| /** | ||
| * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException] | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | |
| * Fetches a new [SessionTransferCredentials]. It will fail with [CredentialsManagerException] |
| * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException] | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | ||
| * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token, | ||
| * if a new one is issued. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * if a new one is issued. | |
| * if a new one is issued. |
| } | ||
|
|
||
| /** | ||
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | |
| * Fetches a new [SessionTransferCredentials]. It will fail with [CredentialsManagerException] |
| * Fetches a new [SessionTransferCredentials] . It will fail with [CredentialsManagerException] | ||
| * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token, | ||
| * if a new one is issued | ||
| * if a new one is issued. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * if a new one is issued. | |
| * if a new one is issued. |
auth0/src/main/java/com/auth0/android/authentication/storage/SecureCredentialsManager.kt
Show resolved
Hide resolved
|
|
||
| /** | ||
| * Helper method to stores the given [SessionTransferCredentials] refresh token in the storage. | ||
| * Method will silently return ,if the passed credentials has no refresh token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Method will silently return ,if the passed credentials has no refresh token. | |
| * Method will silently return if the passed credentials have no refresh token. |
| return | ||
| } | ||
| // Checking if the existing one needs to be replaced with the new one | ||
| if (existingCredentials.refreshToken == sessionTransferCredentials.refreshToken && existingCredentials.idToken == sessionTransferCredentials.idToken) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to check the ID token for equality, as the newer one will have a different iat (issued at) claim value, so the token values will always be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can always replace the old ID token with the new one.
auth0/src/main/java/com/auth0/android/result/SessionTransferCredentials.kt
Outdated
Show resolved
Hide resolved
|
|
||
| /** | ||
| * Holds the session token credentials required for web SSO . | ||
| * Holds the token credentials required for web SSO . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Holds the token credentials required for web SSO . | |
| * Holds the token credentials required for web SSO. |
| public data class SessionTransferCredentials( | ||
| /** | ||
| * The Session Token used for web SSO . | ||
| * The token used for web SSO . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * The token used for web SSO . | |
| * The token used for web SSO. |
auth0/src/main/java/com/auth0/android/result/SessionTransferCredentials.kt
Outdated
Show resolved
Hide resolved
| @field:SerializedName("id_token") public val idToken: String, | ||
|
|
||
| /** | ||
| * Type of the token issued.In this case, an Auth0 web sso token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Type of the token issued.In this case, an Auth0 web sso token | |
| * Type of the token issued. In this case, an Auth0 web sso token. |
auth0/src/main/java/com/auth0/android/result/SessionTransferCredentials.kt
Outdated
Show resolved
Hide resolved
EXAMPLES.md
Outdated
|
|
||
| This feature allows you to authenticate a user in a web session using the refresh token obtained from the native session without requiring the user to log in again. | ||
|
|
||
| Call the API to fetch a webSessionTransferToken in exchange for a refresh token. Use the obtained token to authenticate the user by calling the `/authorize` end point by passing as a query parameter or a cookie value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Call the API to fetch a webSessionTransferToken in exchange for a refresh token. Use the obtained token to authenticate the user by calling the `/authorize` end point by passing as a query parameter or a cookie value. | |
| Call the API to fetch a webSessionTransferToken in exchange for a refresh token. Use the obtained token to authenticate the user by calling the `/authorize` endpoint, passing the token as a query parameter or a cookie value. |
| cookieManager.setAcceptCookie(true) | ||
| cookieManager.setCookie( | ||
| url, | ||
| "session_token=$sessionToken; path=/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should session_token=$sessionToken; path=/ be auth0_session_transfer_token=$sessionToken; path=/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not required anymore. Missed deleting it. Thanks for bringing this to notice
| * * *expiresIn*: The token expiration duration. | ||
| * * *issuedTokenType*: Type of the token issued. | ||
| * | ||
| * Holds the token credentials required for web SSO . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Holds the token credentials required for web SSO . | |
| * Holds the token credentials required for web SSO. |
| public data class SSOCredentials( | ||
| /** | ||
| * The Session Token used for web SSO . | ||
| * The token used for web SSO . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * The token used for web SSO . | |
| * The token used for web SSO. |
| * Expiration duration of the session token in seconds. Session tokens are short-lived and expire after a few minutes. | ||
| * Once expired, the Session Token can no longer be used for SSO. | ||
| * Expiration duration of the session transfer token in seconds. Session transfer tokens are short-lived and expire after a few minutes. | ||
| * Once expired, the session transfer tokens can no longer be used for web SSO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Once expired, the session transfer tokens can no longer be used for web SSO. | |
| * Once expired, the session transfer tokens can no longer be used for web SSO. |
| import com.auth0.android.Auth0 | ||
|
|
||
| /** | ||
| * Provider class to handle native to web sso |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Provider class to handle native to web sso | |
| * Provider class to handle native to web SSO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class is removed
| @field:SerializedName("id_token") public val idToken: String, | ||
|
|
||
| /** | ||
| * Type of the token issued.In this case, an Auth0 session transfer token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Type of the token issued.In this case, an Auth0 session transfer token | |
| * Type of the token issued. In this case, an Auth0 session transfer token. |
I have read the Auth0 general contribution guidelines
I have read the Auth0 Code of Conduct
All existing and new tests complete without errors