├── .gitignore ├── AUTHORS ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE ├── README.md ├── app ├── AndroidManifest.xml ├── build.gradle ├── java │ └── net │ │ └── openid │ │ └── appauthdemo │ │ ├── Application.java │ │ ├── BrowserSelectionAdapter.java │ │ ├── IdentityProvider.java │ │ ├── MainActivity.java │ │ ├── TokenActivity.java │ │ └── package-info.java ├── res │ ├── drawable │ │ ├── appauth_96dp.xml │ │ └── unknown_user_48dp.xml │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_token.xml │ │ └── browser_selector_layout.xml │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ ├── values-v21 │ │ └── styles.xml │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── idp_configs.xml │ │ ├── idp_configs_optional.xml │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── main │ └── res │ └── drawable │ └── solid_background.xml ├── appauth_lockup.svg ├── build.gradle ├── config ├── android-common.gradle ├── checkstyle │ ├── checkstyle.xml │ ├── java.header │ └── java.header.noregex ├── coverage.gradle ├── javadoc.gradle ├── keystore.gradle ├── localprops.gradle ├── style.gradle └── testdeps.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── AndroidManifest.xml ├── build.gradle ├── java │ └── net │ │ └── openid │ │ └── appauth │ │ ├── AdditionalParamsProcessor.java │ │ ├── AppAuthConfiguration.java │ │ ├── AsciiStringListUtil.java │ │ ├── AuthState.java │ │ ├── AuthorizationException.java │ │ ├── AuthorizationManagementActivity.java │ │ ├── AuthorizationRequest.java │ │ ├── AuthorizationResponse.java │ │ ├── AuthorizationService.java │ │ ├── AuthorizationServiceConfiguration.java │ │ ├── AuthorizationServiceDiscovery.java │ │ ├── ClientAuthentication.java │ │ ├── ClientSecretBasic.java │ │ ├── ClientSecretPost.java │ │ ├── Clock.java │ │ ├── CodeVerifierUtil.java │ │ ├── CustomTabManager.java │ │ ├── GrantTypeValues.java │ │ ├── JsonUtil.java │ │ ├── Logger.java │ │ ├── NoClientAuthentication.java │ │ ├── Preconditions.java │ │ ├── RedirectUriReceiverActivity.java │ │ ├── RegistrationRequest.java │ │ ├── RegistrationResponse.java │ │ ├── ResponseTypeValues.java │ │ ├── SystemClock.java │ │ ├── TokenRequest.java │ │ ├── TokenResponse.java │ │ ├── UriUtil.java │ │ ├── Utils.java │ │ ├── browser │ │ ├── AnyBrowserMatcher.java │ │ ├── BrowserBlacklist.java │ │ ├── BrowserDescriptor.java │ │ ├── BrowserMatcher.java │ │ ├── BrowserSelector.java │ │ ├── BrowserWhitelist.java │ │ ├── Browsers.java │ │ ├── DelimitedVersion.java │ │ ├── ExactBrowserMatcher.java │ │ ├── VersionRange.java │ │ ├── VersionedBrowserMatcher.java │ │ └── package-info.java │ │ ├── connectivity │ │ ├── ConnectionBuilder.java │ │ ├── DefaultConnectionBuilder.java │ │ └── package-info.java │ │ └── package-info.java └── javatests │ ├── net │ └── openid │ │ └── appauth │ │ ├── AsciiStringListUtilTest.java │ │ ├── AuthStateTest.java │ │ ├── AuthorizationManagementActivityTest.java │ │ ├── AuthorizationRequestTest.java │ │ ├── AuthorizationResponseTest.java │ │ ├── AuthorizationServiceConfigurationTest.java │ │ ├── AuthorizationServiceDiscoveryTest.java │ │ ├── AuthorizationServiceTest.java │ │ ├── ClientSecretBasicTest.java │ │ ├── ClientSecretPostTest.java │ │ ├── JsonUtilTest.java │ │ ├── LoggerTest.java │ │ ├── NoClientAuthenticationTest.java │ │ ├── PreconditionsTest.java │ │ ├── RedirectUriReceiverActivityTest.java │ │ ├── RegistrationRequestTest.java │ │ ├── RegistrationResponseTest.java │ │ ├── TestClock.java │ │ ├── TestValues.java │ │ ├── TokenRequestTest.java │ │ ├── TokenResponseTest.java │ │ ├── UriUtilTest.java │ │ ├── UtilsTest.java │ │ ├── browser │ │ ├── AnyBrowserMatcherTest.java │ │ ├── BrowserBlacklistTest.java │ │ ├── BrowserDescriptorTest.java │ │ ├── BrowserSelectorTest.java │ │ ├── BrowserWhitelistTest.java │ │ ├── DelimitedVersionTest.java │ │ ├── ExactBrowserMatcherTest.java │ │ ├── VersionRangeTest.java │ │ └── VersionedBrowserMatcherTest.java │ │ └── package-info.java │ └── org │ └── robolectric │ └── shadows │ ├── ShadowIntentFilterFixed.java │ └── package-info.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | build 4 | app/build 5 | library/build 6 | .idea/* 7 | *.iml 8 | appauth.keystore 9 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | # Names should be added to this file as: 5 | # Name or Organization 6 | # The email address is not required for organizations. 7 | 8 | Google Inc. 9 | Rebecka Gulliksson -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to AppAuth 2 | 3 | All contributions to AppAuth for Android are welcome! 4 | 5 | Note that as this library is planned to be used in high-profile production code, 6 | we insist on a very high standards for the code and design, but don't feel shy: 7 | discuss your plans over 8 | [GitHub Issues](https://github.com/openid/AppAuth-Android/issues) and the 9 | [mailing list](http://lists.openid.net/mailman/listinfo/openid-specs-ab), and 10 | send in those pull requests! 11 | 12 | # Signing the Agreements 13 | 14 | In order to contribute to this project, you need to execute two legal agreements 15 | that cover your contributions. Pull requests from users who have not signed 16 | these agreements will not be merged. 17 | 18 | ## Execute the Contributor License Agreement (CLA) 19 | 20 | 1. Visit http://openid.net/contribution-license-agreement/ 21 | 2. Tap *Execute OpenID Foundation Contribution License Agreement* for the 22 | version relevant to you (Individual or Corporate). 23 | 3. Follow the instructions to sign the agreement. 24 | 25 | ## Execute the Working Group Contribution Agreement 26 | 27 | In addition to the Code License Agreement, the OpenID Foundation also requires 28 | a working group contribution agreement to cover any contributions you may make 29 | towards the OpenID Connect spec itself (e.g. in comments, bug reports, feature 30 | requests). 31 | 32 | 1. Visit http://openid.net/intellectual-property/ 33 | 2. Tap *Execute Contributor Agreement By Electronic Signature* in the box 34 | marked *Resources*. 35 | 3. Follow the instructions to sign the document, state `OpenID AB/Connect` as 36 | the Initial Working Group. 37 | 38 | # Making a Pull Request 39 | 40 | ## Before you Start 41 | 42 | Before you work on a big new feature, get in touch to make sure that your work 43 | is inline with the direction of the project and get input on your architecture. 44 | You can file an [Issue](https://github.com/openid/AppAuth-Android/issues) 45 | discussing your proposal, or email the 46 | [list](http://lists.openid.net/mailman/listinfo/openid-specs-ab). 47 | 48 | ## Coding Standards 49 | 50 | The AppAuth library follows the 51 | [Google Coding Style](https://google.github.io/styleguide/javaguide.html) for 52 | the Java language. Please review your own code for adherence to the standard 53 | and make sure to run the `check` gradle target. 54 | 55 | ## Pull Request Reviews 56 | 57 | All pull requests, even by members who have repository write access need to be 58 | reviewed and marked as "LGTM" before they will be merged. 59 | 60 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # Names should be added to this file as: 7 | # Name 8 | 9 | Iain McGinniss 10 | William Denniss 11 | Steven Wright 12 | Alex Chau 13 | Benjamin Franz 14 | Rebecka Gulliksson 15 | Rahul Ravikumar 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | description: "This sample is a quickstart to help you get started with Azure AD B2C on Android using a 3rd party library called AppAuth." 4 | languages: 5 | - java 6 | products: 7 | - azure 8 | - azure-active-directory 9 | urlFragment: integrate-azure-ad-b2c-android-app 10 | --- 11 | 12 | # Integrate Azure AD B2C into an Android application 13 | 14 | This sample demonstrates how to use Azure AD B2C using a 3rd party library called AppAuth. It has only been tested for compatibility in basic scenarios with Azure AD B2C. Issues and feature requests should be directed to the library's open-source project. 15 | 16 | This sample is a quickstart to help you get started with Azure AD B2C on Android using a 3rd party library called AppAuth. The sample is already configured to use a demo environment and can be run simply by downloading the code and building the app on your machine. Follow the instructions below if you would like to use your own Azure AD B2C configuration. 17 | 18 | This sample was adapted from the [original Android AppAuth sample](https://github.com/openid/AppAuth-Android). For more details on how the sample and the library work, please look at the original sample. 19 | 20 | ## Steps to Run 21 | 22 | To use Azure AD B2C, you'll first need to create an Azure AD B2C tenant, register your application, and create some sign in and sign up experiences. 23 | 24 | * To create an Azure AD B2C tenant, checkout [these steps](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-get-started). 25 | 26 | * To register your app, checkout [these steps](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-app-registration). Make sure the "Native Client" switch is turned to "Yes". You will need to supply a Redirect URL with a custom scheme in order for your Android application to capture the callback. To avoid a collision with another application, we recommend using an unique scheme. The example redirect URI in this sample is: `com.onmicrosoft.fabrikamb2c.exampleapp://oauth/redirect`. We recommend replacing fabrikamb2c with your tenant name, and exampleapp with the name of your application. 27 | 28 | * Define your [custom sign in and sign up experience](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-policies). In Azure AD B2C, you define the experience your end users will encounter by creating policies. For this sample, you'll want to create a single combined Sign In/Sign up policy. 29 | 30 | * Clone the code: 31 | 32 | ```git clone https://github.com/Azure-Samples/active-directory-android-native-appauth-b2c.git``` 33 | 34 | ### Setting up the Android App 35 | 36 | 1. In Android Studio, click on "File"->"New"->"Import Project" and select the cloned folder. You will likely get a few errors and need to install some additional tools in Android Studio. Follow the prompts and let Android Studio update the local data. 37 | 38 | **The app is already preconfigured to a demo Azure B2C tenant. At this point, you should be able to build and run the app. Follow the instructions below to configure the app with your own tenant information.** 39 | 40 | > [!NOTE] 41 | >developers using the [Azure China Environment](https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud), MUST use .b2clogin.cn) authority, instead of `login.chinacloudapi.cn`. 42 | > 43 | > The `b2c_redirect_uri` for China should use `com.*` and should be unique. This seems to be an issue with AppAuth accepting redirect Uris. 44 | 45 | 2. Inside `/app/res/values/idp_configs.xml`, replace the following fields: 46 | 47 | * `b2c_tenant`: This is the name of your Azure AD B2C tenant 48 | * `b2c_client_id`: This is your Application ID, which can be found in the Azure Portal (under Application settings). 49 | * `b2c_redirect_uri`: This is your redirect URI, which can be found in the Azure Portal (under Application settings). 50 | * `b2c_signupin_policy`: This is the name of your Sign Up or Sign In policy. 51 | 52 | 3. Inside '/app/build.gradle', replace the value for `appAuthRedirectScheme`. This should correspond to the scheme of the `b2c_redirect_uri` (without the /oauth/redirect). 53 | 54 | 4. Go ahead and try the app. You'll be able to see your custom experience, sign up for an account, and sign in to an existing account. Upon completing the login process, you should see the types of tokens acquired. 55 | 56 | ## Next Steps 57 | 58 | Customize your user experience further by supporting more identity providers. Checkout the docs belows to learn how to add additional providers: 59 | 60 | [Microsoft](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-msa-app) 61 | 62 | [Facebook](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-fb-app) 63 | 64 | [Google](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-goog-app) 65 | 66 | [Amazon](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-amzn-app) 67 | 68 | [LinkedIn](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-li-app) 69 | 70 | 71 | ## Questions & Issues 72 | 73 | Please file any questions or problems with the sample as a github issue. You can also post on [StackOverflow](https://stackoverflow.com/questions/tagged/azure-ad-b2c) with the tag `azure-ad-b2c`. 74 | 75 | This sample was built and tested with the Android Virtual Device Manager on versions 23-24 using Android Studio 2.2.3. 76 | 77 | ## Acknowledgements 78 | 79 | This sample was adapted from the [Android AppAuth sample](https://github.com/openid/AppAuth-Android). 80 | 81 | -------------------------------------------------------------------------------- /app/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 14 | 18 | 19 | 20 | 21 | 29 | 30 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 47 | 48 | 49 | 65 | 66 | 67 | 68 | 69 | 70 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'checkstyle' 3 | apply from: '../config/android-common.gradle' 4 | apply from: '../config/keystore.gradle' 5 | 6 | android { 7 | defaultConfig { 8 | applicationId 'net.openid.appauthdemo' 9 | project.archivesBaseName = 'appauth-demoapp' 10 | vectorDrawables.useSupportLibrary = true 11 | 12 | // replace the below string with your custom redirect scheme. Make sure this is consistent 13 | // with the values used in idp_configs.xml 14 | manifestPlaceholders = [ 15 | 'appAuthRedirectScheme': 'com.onmicrosoft.fabrikamb2c.exampleapp' 16 | ] 17 | } 18 | 19 | signingConfigs { 20 | debugAndRelease { 21 | storeFile file("${rootDir}/appauth.keystore") 22 | storePassword "appauth" 23 | keyAlias "appauth" 24 | keyPassword "appauth" 25 | } 26 | } 27 | 28 | buildTypes { 29 | debug { 30 | signingConfig signingConfigs.debugAndRelease 31 | } 32 | release { 33 | signingConfig signingConfigs.debugAndRelease 34 | } 35 | } 36 | } 37 | 38 | dependencies { 39 | compile fileTree(dir: 'libs', include: ['*.jar']) 40 | compile project(':library') 41 | compile "com.android.support:appcompat-v7:${rootProject.supportLibVersion}" 42 | compile "com.android.support:design:${rootProject.supportLibVersion}" 43 | compile 'com.github.bumptech.glide:glide:3.7.0' 44 | } 45 | 46 | apply from: '../config/style.gradle' 47 | -------------------------------------------------------------------------------- /app/java/net/openid/appauthdemo/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 The AppAuth for Android Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package net.openid.appauthdemo; 16 | 17 | import android.support.v7.app.AppCompatDelegate; 18 | 19 | /** 20 | * Application object; ensures that the support library is correctly configured for use of 21 | * vector drawables. 22 | */ 23 | public class Application extends android.app.Application { 24 | @Override 25 | public void onCreate() { 26 | super.onCreate(); 27 | AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/java/net/openid/appauthdemo/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 The AppAuth for Android Authors. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11 | * express or implied. See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | /** 16 | * App which demonstrates the use of the AppAuth library to authenticate a Google account. 17 | */ 18 | package net.openid.appauthdemo; 19 | -------------------------------------------------------------------------------- /app/res/drawable/appauth_96dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 16 | 20 | 23 | -------------------------------------------------------------------------------- /app/res/drawable/unknown_user_48dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | -------------------------------------------------------------------------------- /app/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 25 | 26 | 32 | 33 | 39 | 40 | 41 | 48 | 49 | 55 | 56 | 60 | 61 | 67 | 68 | 69 | 70 | 74 | 75 | 81 | 82 | 86 | 87 | 94 | 95 | 96 | 104 | 105 | 106 | 107 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /app/res/layout/activity_token.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 25 | 26 | 32 | 33 | 39 | 40 | 46 |