Android SDK
The Kinde Android SDK allows developers to quickly and securely integrate a new or existing application into the Kinde platform.
You can also view the Android docs and Android starter kit in GitHub.
Register for Kinde
Link to this sectionIf you don’t already have a Kinde account, register for free here (no credit card required). Registering gives you a Kinde domain to get started, e.g. https://yourapp.kinde.com
.
Install
Link to this sectionKindeSDK is available through Maven. To install it, simply add the following line to your build.gradle
:
You should also include Retrofit and the GSON converter as dependencies:
Configure Kinde
Link to this sectionSet callback URLs
Link to this section- In Kinde, go to Settings > Applications > [Your app] > View details.
- Add your callback URLs in the relevant fields. For example:
- Allowed callback URLs (also known as redirect URIs):
{your_url_scheme}://<your_kinde_host>//kinde_callback
- for examplemyapp://myhost.kinde.com//kinde_callback
- Allowed logout redirect URLs:
{your_url_scheme}://<your_kinde_host>//kinde_logoutcallback
- for examplemyapp://myhost.kinde.com//kinde_logoutcallback
- Allowed callback URLs (also known as redirect URIs):
- Select Save.
Add environments
Link to this sectionIf you would like to use our Environments feature as part of your development process, you will need to create them within your Kinde account. In this case you would use the Environment subdomain in the code block above.
Configure your app
Link to this sectionEnvironment variables
Link to this sectionThe SDK reads configuration from meta-data
, so you should add meta-data
to the <application>
section of your AndroidManifest.xml
.
You can find these variables in Kinde. Go to Settings > Applications > [Your app] > View details. Then scroll to the App keys section.
au.kinde.domain:
- your Kinde domainau.kinde.clientId
Configuration example:
Integrate with your app
Link to this sectionYou’ll need to import the SDK package in your Android app.
Login / Register
Link to this sectionThe Kinde client provides methods for a simple login / register flow. Add buttons in your view as follows:
Handle redirect
Link to this sectionOnce your user is redirected back to your site from Kinde, it means you’ve logged in successfully. You will need to implement the onNewToken
function from the SDK.
Logout
Link to this sectionThis is implemented in much the same way as logging in or registering. The Kinde SPA client comes with a logout method.
Get user information
Link to this sectionTo access the user information, call the getUserDetails
method.
View users in Kinde
Link to this sectionIn Kinde, go to Users to view all users and subscribers.
User Permissions
Link to this sectionOnce a user has been verified, your application will be returned the JWT token with an array of permissions for that user. You will need to configure your application to read permissions and unlock the respective functions.
Set roles and permissions at the Business level in Kinde. Here’s an example of permissions.
We provide helper functions to more easily access permissions:
A practical example in code might look something like:
Audience
Link to this sectionAn audience
is the intended recipient of an access token - for example the API for your application. The audience argument can be passed to the Kinde client to request an audience to be added to the provided token.
The audience of a token is the intended recipient of the token.
For details on how to connect, see Register an API.
Overriding scope
Link to this sectionBy default the KindeSDK
requests the following scopes:
profile
email
offline
openid
You can override this by passing scope into the KindeSDK
.
Getting claims
Link to this sectionWe have provided a helper to grab any claim from your id or access tokens. The helper defaults to access tokens:
Feature flags
Link to this sectionWe have provided a helper to grab any feature flag from access_token
.
We also provide wrapper functions which should leverage getFlag
above.
Get boolean flags
Get string flags
Get integer flags
Organizations
Link to this sectionCreate an organization
Link to this sectionTo have a new organization created within your application, you will need to run a similar function to below:
Sign up and sign in to organizations
Link to this sectionKinde has a unique code for every organization. You’ll have to pass this code through when you register a new user or sign in to a particular organization. Example function below:
Following authentication, Kinde provides a json web token (jwt) to your application. Along with the standard information, we also include the org_code
and the permissions for that organization. This is important as a user can belong to multiple organizations and have different permissions for each.
Example of a returned token:
The id_token
will also contain an array of organizations that a user belongs to. This is useful if you wanted to build out an organization switcher, for example.
There are two helper functions you can use to extract information:
For more information about how organizations work in Kinde, see Kinde organizations for developers.
Token storage
Link to this sectionOnce the user has successfully authenticated, you’ll have a JWT and possibly a refresh token that should be stored securely.
SDK API reference
Link to this sectionactivity
Link to this sectionActivity of the application.
Type: AppCompatActivity
Required: Yes
loginRedirect
Link to this sectionThe URL that the user will be returned to after authentication.
Type: string
Required: Yes
logoutRedirect
Link to this sectionWhere the user will be redirected when they sign out.
Type: string
Required: Yes
scopes
Link to this sectionType: List<String>
Is required: No
Default:
SDKListener
Link to this sectionThe listener that receives callbacks from the SDK.
Type:
Required: Yes
KindeSDK methods
Link to this sectionlogin
Link to this sectionStarts the authorization flow.
Arguments:
Usage:
register
Link to this sectionStarts the registration flow.
Arguments:
Usage:
createOrg
Link to this sectionStarts the registration flow and creates a new organization in your business.
Arguments:
Usage:
logout
Link to this sectionLogs the user out of Kinde.
Usage: sdk.logout()
isAuthenticated
Link to this sectionChecks that access token is present.
Usage: sdk.isAuthenticated()
Sample output: true
or false
getUserDetails
Link to this sectionGets user details from an access or ID token.
Usage: sdk.getUserDetails()
Sample output:
getClaim
Link to this sectionGets a claim from an access or ID token.
Arguments:
Usage:
Sample output: "David"
getPermission
Link to this sectionReturns the state of a given permission.
Usage:
Sample output:
getPermissions
Link to this sectionReturns all permissions for the current user for the organization they are logged into.
Arguments: permission: String
Usage: sdk.getPermissions()
Sample output:
getUserOrganizations
Link to this sectionGets an array of all organizations the user has access to.
Usage: sdk.getUserOrganizations()
Sample output:
getOrganization
Link to this sectionGet details for the organization your user is signed into.
Usage: sdk.getOrganization()
Sample output:
getFlag
Link to this sectionGets a feature flag from an access token.
Arguments:
Usage: sdk.getFlag("theme");
Sample output:
getBooleanFlag
Link to this sectionGets a boolean feature flag from an access token
Arguments:
Usage:
Sample output: true
or false
getStringFlag
Link to this sectionGets a string feature flag from an access token
Arguments:
Usage:
Sample output: “pink”
getIntegerFlag
Link to this sectionGets a integer feature flag from an access token
Arguments:
Usage:
Sample output: 5
If you need help getting Kinde connected, contact us at support@kinde.com.