This example shows you how to use Okta Mobile Kotlin to authenticate a user. Authentication is done with the browser Chrome Custom Tabs, which open Okta login web-page. After the user authenticates in browser, they are redirected back to the application and exchanging the received code for tokens and persist them.
Before running this sample, you will need the following:
- An Okta Developer Account, you can sign up for one at https://developer.okta.com/signup/.
- An Okta Application, configured for Mobile app.
-
After login, from the Admin dashboard, navigate to Applications→Add Application
-
Choose Native as the platform
-
Populate your new Native OpenID Connect application with values similar to:
Setting Value Application Name Native OpenId Connect App (must be unique) Login URI com.okta.example:/callback End Session URI com.okta.example:/logoutCallback Allowed grant types Authorization Code, Refresh Token (recommended) -
Click Finish to redirect back to the General Settings of your application.
-
Copy the Client ID, as it will be needed for the client configuration.
-
Get your issuer, which is a combination of your Org URL (found in the upper right of the console home page) and /oauth2/default. For example, https://dev-1234.oktapreview.com/oauth2/default.
-
Note: As with any Okta application, make sure you assign Users or Groups to the application. Otherwise, no one can use it.
Update okta.properties in your application directory with the following contents:
issuer=https://${yourOktaDomain}/oauth2/default
clientId=${clientId}
signInRedirectUri=${redirectUri}
signOutRedirectUri=${endSessionUri}Notes:
discovery_urican be customized for specific authorization servers. See Discovery URI Guidance for more info.- To receive a refresh_token, you must include the
offline_accessscope. end_session_redirect_uriis a mandatory parameter.
This sample uses AuthFoundationBootstrap and WebAuthenticationUI from Okta Mobile Kotlin
You can open this sample into Android Studio or build it using gradle.
cd browser-sign-in
./gradlew app:assembleRelease