This starter code shows how to make an OAuth call to get a user token from ARTIK Cloud. It uses AppAuth for Android(an open source OAuth client library) instead of the WebView UI element for improved security. The implemented OAuth method is Authorization Code with PKCE.
- Run the Android app.
- Click Login button.
- Sign in or sign up on the following screen:
- Receive the access token after login succeeds:
- Android Studio
- Android SDK for API level 24
Follow these instructions to create an application using the Developer Dashboard. For this tutorial, select the following:
- Set "Redirect URL" for your application to
cloud.artik.example.oauth://oauth2callback
. - Under Authentication, only check "Authorization Code with PKCE" as AUTH METHODS.
Make a note of your client ID, which you will need in the next step.
- Change
CLIENT_ID
to your own client ID (application ID) at the following lines inConfig.java
:
private static final String CLIENT_ID = "YOUR_CLIENT_ID";
- Make sure
REDIRECT_URI
at the following line inConfig.java
is consistent with "Redirect URL" for your application at the Developer Dashboard:
public static final String REDIRECT_URI = "cloud.artik.example.oauth://oauth2callback";
- Make sure the
intent-filter
field fornet.openid.appauth.RedirectUriReceiverActivity
inAndroidManifest.xml
respects "Redirect URL" for your application at the Developer Dashboard:
<data android:scheme="cloud.artik.example.oauth" android:host="oauth2callback"/>
- Make sure the
appAuthRedirectScheme
at the following line inbuild.gradle
(Module: app) respects "Redirect URL" for your application at the Developer Dashboard:
manifestPlaceholders = [appAuthRedirectScheme: "cloud.artik.example.oauth://oauth2callback"]
- Build the Android project.
Peek into Andriod applications in Tutorials and Samples for more examples.
If you are not familiar with ARTIK Cloud, we have extensive documentation at https://developer.artik.cloud/documentation
The full ARTIK Cloud API specification can be found at https://developer.artik.cloud/documentation/api-reference/
Peek into advanced sample applications at https://developer.artik.cloud/documentation/samples/
To create and manage your services and devices on ARTIK Cloud, visit the Developer Dashboard at https://developer.artik.cloud
Licensed under the Apache License. See LICENSE.
Copyright (c) 2017 Samsung Electronics Co., Ltd.