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 docs in the GitHub repo.

Register for Kinde

Link to this section

If you don’t already have a Kinde account, register for free here (no credit card required).

You will also need a Kinde domain to get started, e.g. yourapp.kinde.com

KindeSDK is available through Maven. To install it, simply add the following line to your build.gradle:

...

implementation 'au.kinde.sdk:<version>'

...

You should also include Retrofit and the GSON converter as dependencies:

...

implementation "com.squareup.retrofit2:retrofit:<version>"

implementation "com.squareup.retrofit2:converter-gson:<version>"

...

Configure Kinde

Link to this section

Set callback URLs

Link to this section
  1. In Kinde, go to Settings > Applications > [Your app] > View details.
  2. 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 example myapp://myhost.kinde.com//kinde_callback - Allowed logout redirect URLs: {your_url_scheme}://<your_kinde_host>//kinde_ logoutcallback - for example myapp://myhost.kinde.com//kinde_ logoutcallback
  3. Select Save.

Add environments

Link to this section

If 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 section

Environment variables

Link to this section

The 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 domain
  • au.kinde.clientId
...
<application ...>
...
	<meta-data
		android:name="au.kinde.domain"
		android:value="your_kinde_url" />
	<meta-data
		android:name="au.kinde.clientId"
		android:value="your_kinde_client_id" />
...
</application>
...

Configuration example:

...
<application ...>
...
	<meta-data
		android:name="au.kinde.domain"
		android:value="app.kinde.com" />\
	<meta-data
		android:name="au.kinde.clientId"
		android:value="test@live" />
...
</application>
...

Integrate with your app

Link to this section

You’ll need to import the SDK package in your Android app.

...
import android.os.Handler
import android.util.Log
...

class YourActivity : AppCompatActivity() {

...
private lateinit var sdk: KindeSDK
...

override fun onCreate(savedInstanceState: Bundle?) {
...
	sdk = KindeSDK(this, object : KindeSDK.SDKListener {

		override fun onNewToken(token: String) {
				// Need to implement
		}

		override fun onLogout() {
				// Need to implement
		}

		override fun onException(exception: Exception) {
			Handler(Looper.getMainLooper()).post {
				Log.e("MyActivity", "Something wrong init KindeSDK: " + exception.message)
			}
		}
	})
...
}

Login / Register

Link to this section

The Kinde client provides methods for a simple login / register flow. Add buttons in your view as follows:

...
findViewById<View>(R.id.b_sign_in).setOnClickListener {
	sdk.login(GrantType.PKCE)
}

findViewById<View>(R.id.b_sign_up).setOnClickListener {
	sdk.register(GrantType.PKCE)
}
...

Handle redirect

Link to this section

Once 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.

...
sdk = KindeSDK(this, object : KindeSDK.SDKListener {
	override fun onNewToken(token: String) {
	// Need to implement\
	}
...
}

This is implemented in much the same way as logging in or registering. The Kinde SPA client comes with a logout method.

findViewById<View>(R.id.b_sign_out).setOnClickListener {
	sdk.logout()
}yar

Get user information

Link to this section

To access the user information, call the getUser method.

sdk.getUser()?.let {
	Handler(Looper.getMainLooper()).post {
			Log.i("MyActivity", it.firstName + " " + it.lastName)
	}
}

View users in Kinde

Link to this section

In Kinde, go to Users to view all users and subscribers.

User Permissions

Link to this section

Once 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.

String[] permissions = {
	"create:todos",
	"update:todos",
	"read:todos",
	"delete:todos",
	"create:tasks",
	"update:tasks",
	"read:tasks",
	"delete:tasks",
}

We provide helper functions to more easily access permissions:

sdk.getPermission("create:todos")
// {orgCode: "org_b235c067b7e4", isGranted: true}

sdk.getPermissions()
// {orgCode: "org_b235c067b7e4", permissions: [ "create:users", "view:users" ]}

A practical example in code might look something like:

if(sdk.getPermission("create:todos").isGranted) {
		// create new a todo
}

An 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.

<meta-data
		android:name="au.kinde.audience"
		android:value="example@example" />

For details on how to connect, see Register an API.

Overriding scope

Link to this section

By default the KindeSDK requests the following scopes:

  • profile
  • email
  • offline
  • openid

You can override this by passing scope into the KindeSDK

sdk = KindeSDK(
	...
	scopes: listOf("openid", "offline", "email", "profile")
	...
)

Getting claims

Link to this section

We have provided a helper to grab any claim from your id or access tokens. The helper defaults to access tokens:

sdk.getClaim("aud")
// ["api.yourapp.com"]

sdk.getClaim("given_name", TokenType.ID_TOKEN)
// "David"

Create an organization

Link to this section

To have a new organization created within your application, you will need to run a similar function to below:

...
findViewById<View>(R.id.create_org).setOnClickListener {
	sdk.createOrg(orgName = "Your Organization")
}
...

Sign up and sign in to organizations

Link to this section

Kinde has a unique code for every organization. You’ll have to pass this code through when you register a new user or sign into a particular organization. Example function below:

findViewById<View>(R.id.b_sign_in).setOnClickListener {
	sdk.login(GrantType.PKCE, orgCode = "your_org_code")
}

findViewById<View>(R.id.b_sign_up).setOnClickListener {
	sdk.register(GrantType.PKCE, orgCode = "your_org_code")
}

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:

{
    "aud": [],
    "exp": 1658475930,
    "iat": 1658472329,
    "iss": "https://your_subdomain.kinde.com",
    "jti": "123457890",
    "org_code": "org_1234",
    "permissions": ["read:todos", "create:todos"],
    "scp": ["openid", "profile", "email", "offline"],
    "sub": "kp:123457890"
}

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.

{
		...
		"org_codes": ["org_1234", "org_4567"],
		...
};

There are two helper functions you can use to extract information:

sdk.getOrganization()
// {'orgCode': 'org_1234'}

sdk.getUserOrganizations()
// {'orgCodes': ['org_1234', 'org_abcd']}

Once 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 section
PropertyTypeIs requiredDefaultDescription
activityAppCompatActivityYesActivity of the application
loginRedirectStringYesThe url that the user will be returned to after authentication
logoutRedirectStringYesWhere your user will be redirected upon logout
scopesList<String>NolistOf("openid", "offline", "email", "profile")List of scopes to override the default ones
SDKListenerSDKListener { fun onNewToken(token: String) fun onLogout() fun onException(exception: Exception)}YesThe listener that receives callbacks from the SDK

KindeSDK methods

Link to this section
PropertyDescriptionArgumentsUsageSample output
loginStarts the authorization flowgrantType: GrantType?, orgCode: String?``// GrantType { PKCE, NONE``}sdk.login(GrantType.PKCE)orsdk.login(GrantType.PKCE, orgCode = "your_org_code")
registerStarts the registration flowgrantType: GrantType?, orgCode: String?sdk.register(GrantType.PKCE)orsdk.register(GrantType.PKCE, orgCode = "your_org_code")
createOrgStarts the registration flow and creates a new organization for your businessgrantType: GrantType?, orgCode: String?sdk.createOrg(orgName = "Your Organization")orsdk.register(GrantType.PKCE, orgName = "Your Organization")
logoutLogs the user out of Kindesdk.logout()
isAuthenticatedChecks that access token is presentsdk.isAuthenticated()true or false
getUserDetailsGets a claim from an access or id tokensdk.getUserDetails(){givenName: "Dave"; id: "abcdef"; familyName: "Smith"; email: dave@smith.com"}
getClaimGets a claim from an access or id tokenclaim: String, tokenType: TokenType``// TokenType { ID_TOKEN, ACCESS_TOKEN``}sdk.getClaim('given_name', TokenType.ID_TOKEN);"David"
getPermissionsReturns all permissions for the current user for the organization they are logged intopermission: Stringsdk.getPermissions(){orgCode: "org_1234", permissions: ["create:todos", "update:todos", "read:todos""create:todos","update:todos","read:todos"]}
getPermissionReturns the state of a given permissionsdk.getPermission("read:todos"){orgCode: "org_1234", isGranted: true}
getUserOrganizationsGets an array of all organizations the user has access tosdk.getUserOrganizations(){orgCodes: ["org_1234", "org_5678""org1_234","org_5678"]}
getOrganizationGet details for the organization your user is logged intosdk.getOrganization(){orgCode: "org_1234"}

If you need any assistance with getting Kinde connected, reach out to us at support@kinde.com.

Talk to us

If you can’t find what you’re looking for in our help center — email our team

Contact us