Skip to content

quick start code for making OAuth2 API call via AppAuth to get a user token from ARTIK Cloud

License

Notifications You must be signed in to change notification settings

artikcloud/tutorial-android-OAuthStarterCode

Repository files navigation

Android OAuth Starter Code

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.

Demo

  • Run the Android app.
  • Click Login button.

GitHub Logo

  • Sign in or sign up on the following screen:

GitHub Logo

  • Receive the access token after login succeeds:

GitHub Logo

Prerequisites

  • Android Studio
  • Android SDK for API level 24

Setup / Installation:

Set up at ARTIK Cloud

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.

Set up your Android project

  • Change CLIENT_ID to your own client ID (application ID) at the following lines in Config.java:
private static final String CLIENT_ID = "YOUR_CLIENT_ID";
  • Make sure REDIRECT_URI at the following line in Config.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 for net.openid.appauth.RedirectUriReceiverActivity in AndroidManifest.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 in build.gradle (Module: app) respects "Redirect URL" for your application at the Developer Dashboard:
manifestPlaceholders = [appAuthRedirectScheme: "cloud.artik.example.oauth://oauth2callback"]
  • Build the Android project.

More examples

Peek into Andriod applications in Tutorials and Samples for more examples.

More about ARTIK Cloud

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

License and Copyright

Licensed under the Apache License. See LICENSE.

Copyright (c) 2017 Samsung Electronics Co., Ltd.

About

quick start code for making OAuth2 API call via AppAuth to get a user token from ARTIK Cloud

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages