-
Notifications
You must be signed in to change notification settings - Fork 663
Mds/okta 524282/okta 528021 update mobile sdk overview #4332
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
0a4b1c6
1ae0c6c
5785b8e
2d285d4
88b0ae4
6f940f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
mauricesharp-okta marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
|
|
||
| Initialize AuthFoundationBootstrap in your `Application` sublcass. This code shows loading the values from a property file in your project. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this. It's repeated further down.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I slightly modified things as there are two things in this para. The first sentence is definitely a repeat. The second is trying to say that the code example is using a property file. I changed the first para to be one sentence:
It's in the next commit. |
||
|
|
||
| First, create a property file, for example, `okta.properties` in the project root. Add the values for your Okta application integration to the file. | ||
|
mauricesharp-okta marked this conversation as resolved.
Outdated
|
||
|
|
||
| ``` | ||
|
mauricesharp-okta marked this conversation as resolved.
Outdated
|
||
| discoveryUrl=https://{yourIssuerUrl}/oauth2/default/.well-known/openid-configuration | ||
| clientId={yourClientId} | ||
| redirectUri=com.okta.sample.android:/login | ||
| ``` | ||
|
|
||
| Add this configuration to your `app/build.gradle` to make the properties available in the build configuration: | ||
|
|
||
| ```gradle | ||
| def oktaProperties = new Properties() | ||
| rootProject.file("okta.properties").withInputStream { oktaProperties.load(it) } | ||
|
|
||
| defaultConfig { | ||
| ... | ||
|
|
||
| buildConfigField "String", 'DISCOVERY_URL', "\"${oktaProperties.getProperty('discoveryUrl')}\"" | ||
| buildConfigField "String", 'CLIENT_ID', "\"${oktaProperties.getProperty('clientId')}\"" | ||
| buildConfigField "String", 'REDIRECT_URI', "\"${oktaProperties.getProperty('redirectUri')}\"" | ||
|
|
||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| In your `Applicaiton` subclass, initialize `AuthFoundationBootstrap` from the `BuildConfig` by calling `initializeAuthFoundation` from `onCreate`. | ||
|
rajdeepnanua-okta marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```kotlin | ||
| import com.okta.android.samples.authenticator.BuildConfig | ||
| import com.okta.authfoundation.AuthFoundationDefaults | ||
| import com.okta.authfoundation.client.OidcClient | ||
| import com.okta.authfoundation.client.OidcConfiguration | ||
| import com.okta.authfoundation.client.SharedPreferencesCache | ||
| import com.okta.authfoundation.credential.CredentialDataSource.Companion.createCredentialDataSource | ||
| import com.okta.authfoundationbootstrap.CredentialBootstrap | ||
| import okhttp3.HttpUrl.Companion.toHttpUrl | ||
|
|
||
| fun initializeAuthFoundation() { | ||
| // Initializes Auth Foundation and Credential Bootstrap classes. | ||
| AuthFoundationDefaults.cache = SharedPreferencesCache.create(this) | ||
| val oidcConfiguration = OidcConfiguration( | ||
| clientId = BuildConfig.CLIENT_ID, | ||
| defaultScope = "openid email profile offline_access", | ||
| ) | ||
| val client = OidcClient.createFromDiscoveryUrl( | ||
| oidcConfiguration, | ||
| BuildConfig.DISCOVERY_URL.toHttpUrl(), | ||
| ) | ||
| CredentialBootstrap.initialize(client.createCredentialDataSource(this)) | ||
| } | ||
| ``` | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <div class="full"> | ||
|
|
||
|  | ||
|
|
||
| </div> | ||
|
|
||
| The main objects associated with each step in the flow are: | ||
|
|
||
| | Sign-in step | Objects | | ||
| | :--------------------------------- |:---------------------------------| | ||
| | Initialize SDK | InteractionCodeFlow | | ||
| | Request initial step | InteractionCodeFlow | | ||
| | Receive step | IdxResponse | | ||
| | Check completion, cancel, or error | IdxResponse <br/> IdxRemediation | | ||
| | Gather user input | IdxRemediation <br/> Capability | | ||
| | Send input | InteractionCodeFlow | | ||
| | Done | IdxResponse | | ||
|
mauricesharp-okta marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,42 +1,21 @@ | ||||||||
| This code assumes storing the access token after a successful sign-in flow: | ||||||||
|
|
||||||||
| ```kotlin | ||||||||
| import com.okta.authfoundation.client.OidcClientResult | ||||||||
| import com.okta.authfoundation.credential.RevokeTokenType | ||||||||
| import com.okta.authfoundationbootstrap.CredentialBootstrap | ||||||||
|
|
||||||||
| fun logout() { | ||||||||
| viewModelScope.launch(Dispatchers.IO) { | ||||||||
| try { | ||||||||
| // First load a refresh token if one exists. | ||||||||
| val refreshToken = Storage.tokens.refreshToken | ||||||||
| if (refreshToken != null) { | ||||||||
| // Revoking the refresh token also revokes the access token. | ||||||||
| revokeToken("refresh_token", refreshToken) | ||||||||
| } else { | ||||||||
| revokeToken("access_token", Storage.tokens.accessToken) | ||||||||
| viewModelScope.launch { | ||||||||
| // Revoking the refresh token also revokes the access token. | ||||||||
| when (val revokeResult = CredentialBootstrap.defaultCredential().revokeToken(RevokeTokenType.REFRESH_TOKEN)) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to split kotlin code over two lines? This one runs out of the browser window.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did the best I could... in the next commit. |
||||||||
| is OidcClientResult.Error -> { | ||||||||
| // Sign-out failed, handle the error. | ||||||||
| } | ||||||||
| is OidcClientResult.Success -> { | ||||||||
| // Sign-out successful. Redirect to a sign-in view. | ||||||||
| } | ||||||||
|
|
||||||||
| // Sign-out successful. Redirect to a sign-in view. | ||||||||
| } catch (e: Exception) { | ||||||||
| // Sign-out failed, handle the error. | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
| private fun revokeToken(tokenType: String, token: String) { | ||||||||
| // Create an API request to revoke the token. | ||||||||
| val formBody = FormBody.Builder() | ||||||||
| .add("client_id", BuildConfig.CLIENT_ID) | ||||||||
| .add("token_type_hint", tokenType) | ||||||||
| .add("token", token) | ||||||||
| .build() | ||||||||
|
|
||||||||
| val request = Request.Builder() | ||||||||
| .url("${BuildConfig.ISSUER}/v1/revoke") | ||||||||
| .post(formBody) | ||||||||
| .build() | ||||||||
|
|
||||||||
| // Send the request to revoke the token. | ||||||||
| val response = OktaIdxClientConfigurationProvider.get().okHttpCallFactory.newCall(request).execute() | ||||||||
|
|
||||||||
| println("Revoke Token Response: $response") | ||||||||
| } | ||||||||
| ``` | ||||||||
Uh oh!
There was an error while loading. Please reload this page.