Skip to content

Commit

Permalink
Merge pull request #22 from Achintha444/main
Browse files Browse the repository at this point in the history
docs: improve doc site
  • Loading branch information
Achintha444 authored May 13, 2024
2 parents 8318128 + cac6988 commit 93e6f10
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 142 deletions.
25 changes: 21 additions & 4 deletions docs/website/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,40 @@ export default defineConfig({
ignoreDeadLinks: true,
title: "Mobile SDKs",
description: "Welcome to our comprehensive documentation site for Mobile SDKs for Asgardeo! Here, you'll find everything you need to seamlessly integrate Asgardeo's authentication and identity management solutions into your mobile applications.",
head: [["link", { rel: "icon", href: "/mobile-ui-sdks/asgardeo-dark.svg" }]],
head: [
[
"link",
{ rel: "icon", href: "/mobile-ui-sdks/asgardeo-dark.svg" }
]
],
themeConfig: {
siteTitle: "Mobile SDKs",
search: {
provider: 'local'
},
logo: {
light: "/asgardeo-light.svg",
dark: "/asgardeo-dark.svg",
},
nav: [
{ text: "Home", link: "/" },
{ text: "Android SDK", link: "/android/getting-started.html" }
{ text: "Android SDK", link: "/android/introduction.html" }
],

sidebar: [
{
text: "Android SDK",
items: [
{ text: "Getting Started", link: "/android/getting-started" },
{
text: "Getting Started",
items: [
{ text: "Introduction", link: "/android/introduction.html" },
{ text: "Start", link: "/android/start.html" },
{ text: "Get User Details", link: "/android/user-details.html" },
{ text: "Get Token Information", link: "/android/token-information.html" },
{ text: "Logout", link: "/android/logout.html" },
{ text: "Client Attestation", link: "/android/client-attestation.html" },
]
},
{ text: "Use Authenticators", link: "/android/use-authenticators" },
{ text: "APIs", link: "/android/apis" }
]
Expand Down
55 changes: 55 additions & 0 deletions docs/website/android/client-attestation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!--
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
-->

# Client Attestation
You can also use client attestation with the SDK as well.

## How to setup client attestation for your application

1. In the created mobile application in Asgardeo, go **Advanced** and check **Enable client attestation**.
2. Subscribe to the "Google Play Integrity API" from your Google Cloud project. You can do this from **Enabled API's & Services** in your Google Cloud project.
3. Create a new service account in the Google project. You can create a Service Account for yourself with the following steps.

1. In your Google project, go to **IAM & Admin** -> **Service Accounts**.
2. Click **Create Service Account**.
3. Fill in the name and click **Create**.
4. Grant your service account the roles of Service Account User and Service Usage Consumer.
5. Click **Continue** and then **Done**
6. You can see the service account added without keys, go to **Actions** -> **Manage Keys** on the service account.
7. Click **Add** key and Select `JSON`.
8. Save the JSON in a secure place as this is required for Android Attestation Credentials for application metadata.

4. After that, update the Application's Advanced properties. The application you created requires two properties to perform Android attestation.

1. Android package name
2. `androidAttestationServiceCredentials`
The downloaded JSON secret of the Service Account. Note that this attribute is defined as a JSON object hence use the JSON key as it is.

5. Now you can call the **Google Play Integrity API** from your application and pass the integrity token that you will get from the API result to the `integrityToken` value of the `AuthenticationCoreConfig`.

```kotlin
private val asgardeoAuth: AsgardeoAuth = AsgardeoAuth.getInstance(
AuthenticationCoreConfig(
discoveryEndpoint = "https://api.asgardeo.io/t/<org_name>/oauth2/token/.well-known/openid-configuration",
redirectUri = "wso2sample://oauth2",
clientId = "<client_id>",
scope = "openid profile",
integrityToken = "<integrity_token>" // [!code highlight]
)
)
```
62 changes: 62 additions & 0 deletions docs/website/android/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
-->

# Asgardeo Android SDK

The Asgardeo Auth Android SDK enables Android applications (written in Kotlin) to utilize OpenID Connect (OIDC) authentication with Asgardeo serving as the Consumer Identity and Access Management (CIAM) Provider through application-native authentication.

This SDK assists you in creating custom login flows directly within the applications themselves, without relying on browser redirects, thereby prioritizing user experience.

## Requirements and recommendations

* An Android application written in Kotlin programming language.
* The minimum supported SDK is API level 26, compiled to API level 34. However, there are certain limitations when using specific authentication methods:
* Passkeys are only supported on API level 34 and above.
* Google authentication using the Credential Manager API is supported on API level 34 and above.

## Getting Started

### Prerequisites

- [Register to Asgardeo and create an organization if you don't already have one](https://wso2.com/asgardeo/docs/get-started/create-asgardeo-account/). The organization name you choose will be referred to as `<org_name>` throughout this document.
- [Register a mobile application in Asgardeo to integrate your application with Asgardeo](https://wso2.com/asgardeo/docs/guides/applications/register-mobile-app/). You will obtain a `client_id` from Asgardeo for your application which will need to be embedded later for the SDK integration. Also note the redirect URI that you used to create the application, this is also required for the SDK integration.
- In the created mobile application, go to the **Advanced** tab and [enable the application native authentication for your Android application](https://is.docs.wso2.com/en/latest/guides/authentication/add-application-native-login/#enable-app-native-authentication).

### Installing the SDK

1. Open the `build.gradle` file of your Android application and add the following dependency to add the latest released SDK.

```groovy
dependencies {
implementation 'io.asgardeo:android:<latest-version>'
}
```
You can find the latest version of the SDK from the [Maven Repository](https://central.sonatype.com/artifact/io.asgardeo/android.ui).
2. Add a redirect scheme in the Android application. You need to add the `appAuthRedirectScheme` in the application `build.gradle` file.
This should be consistent with the CallBack URL of the Service Provider that you configured in the Asgardeo.
For example, if you have configured the CallBack URL as *wso2sample://oauth2*, then the `appAuthRedirectScheme` should be *wso2sample*.
```groovy
android.defaultConfig.manifestPlaceholders = [
'appAuthRedirectScheme': 'wso2sample' // [!code highlight]
]
```
25 changes: 25 additions & 0 deletions docs/website/android/logout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
-->

# Logout

If you want to perform a logout, you can call the `logout` function in the <a href="/mobile-ui-sdks/android/api/core/io.asgardeo.android.core.provider.providers.authentication/-authentication-provider/index.html" target="_blank">AuthenticationProvider</a>. This will emit the state **AuthenticationState.Initial** if the logout is successful, and if an error occurs, it will emit **AuthenticationState.Error**.

```kotlin
authenticationProvider.logout(context)
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,8 @@
* specific language governing permissions and limitations
* under the License.
-->
# Asgardeo Android SDK

The Asgardeo Auth Android SDK enables Android applications (written in Kotlin) to utilize OpenID Connect (OIDC) authentication with Asgardeo serving as the Consumer Identity and Access Management (CIAM) Provider through application-native authentication.

This SDK assists you in creating custom login flows directly within the applications themselves, without relying on browser redirects, thereby prioritizing user experience.

## Requirements and recommendations

* An Android application written in Kotlin programming language.
* The minimum supported SDK is API level 26, compiled to API level 34. However, there are certain limitations when using specific authentication methods:
* Passkeys are only supported on API level 34 and above.
* Google authentication using the Credential Manager API is supported on API level 34 and above.

## Getting Started

### Prerequisites

- [Register to Asgardeo and create an organization if you don't already have one](https://wso2.com/asgardeo/docs/get-started/create-asgardeo-account/). The organization name you choose will be referred to as `<org_name>` throughout this document.
- [Register a mobile application in Asgardeo to integrate your application with Asgardeo](https://wso2.com/asgardeo/docs/guides/applications/register-mobile-app/). You will obtain a `client_id` from Asgardeo for your application which will need to be embedded later for the SDK integration. Also note the redirect URI that you used to create the application, this is also required for the SDK integration.
- In the created mobile application, go to the **Advanced** tab and [enable the application native authentication for your Android application](https://is.docs.wso2.com/en/latest/guides/authentication/add-application-native-login/#enable-app-native-authentication).

### Installing the SDK

1. Open the `build.gradle` file of your Android application and add the following dependency to add the latest released SDK.

```groovy
dependencies {
implementation 'io.asgardeo:android:<latest-version>'
}
```
You can find the latest version of the SDK from the [Maven Repository](https://central.sonatype.com/artifact/io.asgardeo/android.ui).
2. Add a redirect scheme in the Android application. You need to add the `appAuthRedirectScheme` in the application `build.gradle` file.
This should be consistent with the CallBack URL of the Service Provider that you configured in the Asgardeo.
For example, if you have configured the CallBack URL as *wso2sample://oauth2*, then the `appAuthRedirectScheme` should be *wso2sample*.
```groovy
android.defaultConfig.manifestPlaceholders = [
'appAuthRedirectScheme': 'wso2sample' // [!code highlight]
]
```
### Start the authentication process
# Start the Authentication Process

1. Initialize the SDK object `AsgardeoAuth`, to authenticate users into your application. This can be done in a repository if you are using an [MVVM](https://www.geeksforgeeks.org/mvvm-model-view-viewmodel-architecture-pattern-in-android/) pattern in your application.

Expand Down Expand Up @@ -205,93 +161,3 @@ fun BasicAuthComponent(
```

You will not need to handle the authentication state in multiple places, you can do it at the start of the application, and it will handle the state accordingly.

### Get user details

After the user is authenticated, to get user-related information, we can use the following function. This will return the user details in a `LinkedHashMap`.

```kotlin
coroutineScope.launch {
runCatching {
authenticationProvider.getUserDetails(<context>) // [!code highlight]
}.onSuccess { userDetails ->
Profile(userDetails)
}.onFailure { e ->
// Display error message
}
}
```

### Get token information

To get information, you can use the <a href="mobile-ui-sdks/android/api/core/io.asgardeo.android.core.provider.providers.token/-token-provider/index.html" target="_blank">TokenProvider</a>. This will assist you in getting token-related information and performing actions on the tokens.

```kotlin
val tokenProvider: TokenProvider = asgardeoAuth.getTokenProvider()
```

To get the token-related information, you can use the following functions:

```kotlin
val accessToken: String? = tokenProvider.getAccessToken(context)
val idToken: String? = tokenProvider.getIDToken(context)
val refreshToken: String? = tokenProvider.getRefreshToken(context)
val accessTokenExpirationTime: Long? = tokenProvider.getAccessTokenExpirationTime(context)
val scope:String? = tokenProvider.getScope(context)
```

### Perform action based on the tokens

If you want to perform any action based on the tokens that are returned, you can use the `performAction` function in the <a href="mobile-ui-sdks/android/api/core/io.asgardeo.android.core.provider.providers.token/-token-provider/index.html" target="_blank">TokenProvider</a>.

```kotlin
tokenProvider.performAction(context) { accessToken, idToken, ->
action(accessToken, idToken)
}
```

### Logout

If you want to perform a logout, you can call the `logout` function in the <a href="/mobile-ui-sdks/android/api/core/io.asgardeo.android.core.provider.providers.authentication/-authentication-provider/index.html" target="_blank">AuthenticationProvider</a>. This will emit the state **AuthenticationState.Initial** if the logout is successful, and if an error occurs, it will emit **AuthenticationState.Error**.

```kotlin
authenticationProvider.logout(context)
```

### Client attestation
You can also use client attestation with the SDK as well.

#### How to setup client attestation for your application

1. In the created mobile application in Asgardeo, go **Advanced** and check **Enable client attestation**.
2. Subscribe to the "Google Play Integrity API" from your Google Cloud project. You can do this from **Enabled API's & Services** in your Google Cloud project.
3. Create a new service account in the Google project. You can create a Service Account for yourself with the following steps.
1. In your Google project, go to **IAM & Admin** -> **Service Accounts**.
2. Click **Create Service Account**.
3. Fill in the name and click **Create**.
4. Grant your service account the roles of Service Account User and Service Usage Consumer.
5. Click **Continue** and then **Done**
6. You can see the service account added without keys, go to **Actions** -> **Manage Keys** on the service account.
7. Click **Add** key and Select `JSON`.
8. Save the JSON in a secure place as this is required for Android Attestation Credentials for application metadata.
4. After that, update the Application's Advanced properties. The application you created requires two properties to perform Android attestation.

1. Android package name
2. `androidAttestationServiceCredentials`
The downloaded JSON secret of the Service Account. Note that this attribute is defined as a JSON object hence use the JSON key as it is.

5. Now you can call the **Google Play Integrity API** from your application and pass the integrity token that you will get from the API result to the `integrityToken` value of the `AuthenticationCoreConfig`.

```kotlin
private val asgardeoAuth: AsgardeoAuth = AsgardeoAuth.getInstance(
AuthenticationCoreConfig(
discoveryEndpoint = "https://api.asgardeo.io/t/<org_name>/oauth2/token/.well-known/openid-configuration",
redirectUri = "wso2sample://oauth2",
clientId = "<client_id>",
scope = "openid profile",
integrityToken = "<integrity_token>" // [!code highlight]
)
)
```
45 changes: 45 additions & 0 deletions docs/website/android/token-information.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!--
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
-->

# Get Token Information

To get information, you can use the <a href="mobile-ui-sdks/android/api/core/io.asgardeo.android.core.provider.providers.token/-token-provider/index.html" target="_blank">TokenProvider</a>. This will assist you in getting token-related information and performing actions on the tokens.

```kotlin
val tokenProvider: TokenProvider = asgardeoAuth.getTokenProvider()
```

To get the token-related information, you can use the following functions:

```kotlin
val accessToken: String? = tokenProvider.getAccessToken(context)
val idToken: String? = tokenProvider.getIDToken(context)
val refreshToken: String? = tokenProvider.getRefreshToken(context)
val accessTokenExpirationTime: Long? = tokenProvider.getAccessTokenExpirationTime(context)
val scope:String? = tokenProvider.getScope(context)
```

## Perform action based on the tokens

If you want to perform any action based on the tokens that are returned, you can use the `performAction` function in the <a href="mobile-ui-sdks/android/api/core/io.asgardeo.android.core.provider.providers.token/-token-provider/index.html" target="_blank">TokenProvider</a>.

```kotlin
tokenProvider.performAction(context) { accessToken, idToken, ->
action(accessToken, idToken)
}
```
Loading

0 comments on commit 93e6f10

Please sign in to comment.