Giter Site home page Giter Site logo

azure-samples / active-directory-b2c-android-native-msal Goto Github PK

View Code? Open in Web Editor NEW
6.0 50.0 10.0 24.94 MB

This is a simple Android app showcasing how to use MSAL to authenticate users via Azure Active Directory B2C, and access a Web API with the resulting tokens.

Home Page: http://aka.ms/aadb2c

License: MIT License

Java 100.00%
microsoft identity azure-ad-b2c azure-active-directory android mobile msal

active-directory-b2c-android-native-msal's Introduction

Integrate Azure AD B2C into an Android App Using MSAL

This sample has been archived.

Please see the new version of our B2C sample with Android here.

Should you still wish to view this sample in its archived state, please switch to the master branch.

active-directory-b2c-android-native-msal's People

Contributors

danieldobalian avatar iambmelt avatar parakhj avatar saeedakhter-msft avatar supernova-eng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

active-directory-b2c-android-native-msal's Issues

How to access the refresh token?

The AuthenticationResult at AuthenticationCallback success only gives the access token. How do we get the refresh token using this implementation?

System.MissingMethodException: Method 'Android.Support.CustomTabs.CustomTabsIntent.LaunchUrl' not found.

Hi,

Experiencing exception in Azure B2C Directory login by using MSAL Library on Android platform with the following two libraries when updated to latest version (26.1.0.1)

  1. Xamarin.Android.Support.CustomTabs (version 26.1.0.1)
  2. Xamarin.Android.Support.v4 (version 26.1.0.1)

Please download sample from the following Link:

https://github.com/Azure-Samples/active-directory-b2c-android-native-msal

Exception:

System.MissingMethodException: Method 'Android.Support.CustomTabs.CustomTabsIntent.LaunchUrl' not found.

StackTrace:

MonoDroid( 7659): UNHANDLED EXCEPTION:
MonoDroid( 7659): System.MissingMethodException: Method 'Android.Support.CustomTabs.CustomTabsIntent.LaunchUrl' not found.
MonoDroid( 7659): at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] :0
MonoDroid( 7659): at (wrapper dynamic-method) S
An unhandled exception occured.

Problem with subsequent Google Logins after Logout

For the very first time, when attempting to login using Google, user is prompted for selecting the google accounts.. After logout from the application, subsequent logins doesn't prompt for selecting the google accounts, and directly logins with the previous google account..
Kindly help me out in resolving this issue.

System.MissingMethodException: Method 'Android.Support.CustomTabs.CustomTabsIntent.LaunchUrl' not found.

Hi,

Experiencing exception in Azure B2C Directory login by using MSAL Library on Android platform with the following two libraries when updated to latest version (26.1.0.1)

  1. Xamarin.Android.Support.CustomTabs (version 26.1.0.1)
  2. Xamarin.Android.Support.v4 (version 26.1.0.1)

Please download sample from the following Link:

https://github.com/Azure-Samples/active-directory-b2c-android-native-msal

Exception:

System.MissingMethodException: Method 'Android.Support.CustomTabs.CustomTabsIntent.LaunchUrl' not found.

StackTrace:

MonoDroid( 7659): UNHANDLED EXCEPTION:
MonoDroid( 7659): System.MissingMethodException: Method 'Android.Support.CustomTabs.CustomTabsIntent.LaunchUrl' not found.
MonoDroid( 7659): at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] :0
MonoDroid( 7659): at (wrapper dynamic-method) S
An unhandled exception occured.

Token request failed with error

Just download and run the app, getting following error message (I copied few lines before):

D/AuthenticationActivity: MSAL_LOG: MSAL 0.1.1 Android 25 [2017-05-12 04:47:37] ChromeCustomTab support is available, launching chrome tab.
I/BrowserTabActivity: MSAL 0.1.1 Android 25 [2017-05-12 04:48:40] BrowserTabActivity onCreate: received redirect from system webview.
D/BrowserTabActivity: MSAL_LOG: MSAL 0.1.1 Android 25 [2017-05-12 04:48:40] BrowserTabActivity onCreate: received redirect from system webview.
I/AuthenticationActivity: MSAL 0.1.1 Android 25 [2017-05-12 04:48:40] onNewIntent is called, received redirect from system webview.
D/AuthenticationActivity: MSAL_LOG: MSAL 0.1.1 Android 25 [2017-05-12 04:48:40] onNewIntent is called, received redirect from system webview.
I/AuthenticationActivity: MSAL 0.1.1 Android 25 [2017-05-12 04:48:40] Return to caller with resultCode: 2003; requestId: 198602100
D/AuthenticationActivity: MSAL_LOG: MSAL 0.1.1 Android 25 [2017-05-12 04:48:40] Return to caller with resultCode: 2003; requestId: 198602100
I/InteractiveRequest: MSAL 0.1.1 Android 25 [2017-05-12 04:48:41] Received request code is: 1001; result code is: 2003
D/InteractiveRequest: MSAL_LOG: MSAL 0.1.1 Android 25 [2017-05-12 04:48:41] Received request code is: 1001; result code is: 2003
I/AuthorizationResult: MSAL 0.1.1 Android 25 [2017-05-12 04:48:41] Auth code is successfully returned from webview redirect.
D/AuthorizationResult: MSAL_LOG: MSAL 0.1.1 Android 25 [2017-05-12 04:48:41] Auth code is successfully returned from webview redirect.
I/InteractiveRequest: MSAL 0.1.1 Android 25 [2017-05-12 04:48:41 - 1f1f9d68-67da-438a-8919-aeaf327c3d4b] Authorize request status is: SUCCESS
D/InteractiveRequest: MSAL_LOG: MSAL 0.1.1 Android 25 [2017-05-12 04:48:41 - 1f1f9d68-67da-438a-8919-aeaf327c3d4b] Authorize request status is: SUCCESS
V/HttpRequest: MSAL 0.1.1 Android 25 [2017-05-12 04:48:41 - 1f1f9d68-67da-438a-8919-aeaf327c3d4b] Sending Http Post request.
D/HttpRequest: MSAL_LOG: MSAL 0.1.1 Android 25 [2017-05-12 04:48:41 - 1f1f9d68-67da-438a-8919-aeaf327c3d4b] Sending Http Post request.
E/BaseRequest: MSAL 0.1.1 Android 25 [2017-05-12 04:48:42 - 1f1f9d68-67da-438a-8919-aeaf327c3d4b] Token request failed with error: unexpected end of stream on Connection{login.microsoftonline.com:443, proxy=DIRECT hostAddress=104.41.216.17 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA protocol=http/1.1} (recycle count=0) java.io.IOException: unexpected end of stream on Connection{login.microsoftonline.com:443, proxy=DIRECT hostAddress=104.41.216.17 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA protocol=http/1.1} (recycle count=0)
at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:210)
at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:906)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:782)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:463)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
at com.microsoft.identity.client.HttpRequest.executeHttpSend(HttpRequest.java:185)
at com.microsoft.identity.client.HttpRequest.sendWithRetry(HttpRequest.java:151)
at com.microsoft.identity.client.HttpRequest.send(HttpRequest.java:132)
at com.microsoft.identity.client.HttpRequest.sendPost(HttpRequest.java:109)
at com.microsoft.identity.client.Oauth2Client.executeHttpRequest(Oauth2Client.java:142)
at com.microsoft.identity.client.Oauth2Client.getToken(Oauth2Client.java:77)
at com.microsoft.identity.client.BaseRequest.performTokenRequest(BaseRequest.java:173)
at com.microsoft.identity.client.BaseRequest$1.run(BaseRequest.java:107)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.io.EOFException: \n not found: size=0 content=...
at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:200)
at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)

Msal Library is taking too much time to throw MSAL exception in Failure case

Please find the log where I have try 2 attempts and it taking more then 2 and 5 min of time to throw the exception in case of failure

Attempt 1
Line 251: 11-26 21:23:36.731
Line 91: 11-26 21:21:03.109
Time Taken by MSAL: 00-00 00:02:33.622

Attempt 1
Line 461: 11-26 21:36:13.927
Line 371: 11-26 21:31:13.689
Time Taken by MSAL: 00-00 00:05:00.238

Is There Any way is there to reduce this time when Msal is throwing the Exception withing 40sec instead of 2 or 5+ minute for the good experience??
Any work arround solution for this from MSAL end
as in 1st attempt the correlation id had not returned in the header of response.So it took 2min.33sec.622ms
as in 2st attempt the Request timeout with SocketTimeoutException and its retry one more time but that Token request failed with error as Connection reset by peer.So it took 5min.0sec.238ms

Log Details start here related to MSAL.

Line 91: 11-26 21:21:03.109 7703-7703/com.package.name I/PublicClientApplication: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03] Create new public client application.
Line 92: 11-26 21:21:03.123 7703-7703/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03] Passed in authority string is a b2c authority, create a new b2c authority instance.
Line 97: 11-26 21:21:03.126 7703-7703/com.package.name V/TokenCache: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03 - d8f10a6d-28e0-4ff0-81f0-af02c830470e] Retrieve users with the given client id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Line 102: 11-26 21:21:03.150 7703-7703/com.package.name V/TokenCache: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03 - d8f10a6d-28e0-4ff0-81f0-af02c830470e] Retrieve all the refresh tokens for given client id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx; Returned refresh token number is 1
Line 103: 11-26 21:21:03.152 7703-7703/com.package.name I/TAGAzureUtils: initializeMSAL:getAuthSilentCallback
Line 104: 11-26 21:21:03.154 7703-7703/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03] Passed in authority string is a b2c authority, create a new b2c authority instance.
Line 105: 11-26 21:21:03.155 7703-7703/com.package.name I/PublicClientApplication: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Preparing a new silent request
Line 107: 11-26 21:21:03.179 7703-7806/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03] Passed in authority string is a b2c authority, create a new b2c authority instance.
Line 108: 11-26 21:21:03.180 7703-7806/com.package.name V/TokenCache: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Access token item found in the cache is already expired.
Line 109: 11-26 21:21:03.192 7703-7806/com.package.name V/TokenCache: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Retrieve refresh tokens for the given cache key
Line 110: 11-26 21:21:03.193 7703-7806/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Perform authority validation and tenant discovery.
Line 111: 11-26 21:21:03.219 7703-7806/com.package.name V/HttpRequest: MSAL 0.1.1 Android 23 [2017-11-26 15:51:03 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Sending Http Get request.
Line 160: 11-26 21:21:40.197 7703-7806/com.package.name V/HttpRequest: MSAL 0.1.1 Android 23 [2017-11-26 15:51:40 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Returned status code is: 200
Line 161: 11-26 21:21:40.202 7703-7806/com.package.name W/Oauth2Client: MSAL 0.1.1 Android 23 [2017-11-26 15:51:40 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Returned response doesn't have correlation id in the header.
Line 162: 11-26 21:21:40.210 7703-7806/com.package.name I/Oauth2Client: MSAL 0.1.1 Android 23 [2017-11-26 15:51:40 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Http response status code is: 200
Line 163: 11-26 21:21:40.217 7703-7806/com.package.name V/HttpRequest: MSAL 0.1.1 Android 23 [2017-11-26 15:51:40 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Sending Http Post request.
Line 186: 11-26 21:23:36.691 7703-7806/com.package.name E/BaseRequest: MSAL 0.1.1 Android 23 [2017-11-26 15:53:36 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Token request failed with error: Read error: ssl=0x7f1904918e00: I/O error during system call, Connection reset by peer javax.net.ssl.SSLException: Read error: ssl=0x7f1904918e00: I/O error during system call, Connection reset by peer
Line 215: 11-26 21:23:36.722 7703-7806/com.package.name E/BaseRequest: MSAL 0.1.1 Android 23 [2017-11-26 15:53:36 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Error occurred during authentication. com.microsoft.identity.client.MsalClientException: Auth failed with the error Read error: ssl=0x7f1904918e00: I/O error during system call, Connection reset by peer
Line 215: 11-26 21:23:36.722 7703-7806/com.package.name E/BaseRequest: MSAL 0.1.1 Android 23 [2017-11-26 15:53:36 - ea5e7220-d718-4909-9d19-ae20ac323cf1] Error occurred during authentication. com.microsoft.identity.client.MsalClientException: Auth failed with the error Read error: ssl=0x7f1904918e00: I/O error during system call, Connection reset by peer
Line 251: 11-26 21:23:36.731 7703-7703/com.package.name I/TAGAzureUtils: getAuthSilentCallback Authentication failed: com.microsoft.identity.client.MsalClientException: Auth failed with the error Read error: ssl=0x7f1904918e00: I/O error during system call, Connection reset by peer
Line 371: 11-26 21:31:13.689 7703-7703/com.package.name I/PublicClientApplication: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13] Create new public client application.
Line 372: 11-26 21:31:13.711 7703-7703/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13] Passed in authority string is a b2c authority, create a new b2c authority instance.
Line 373: 11-26 21:31:13.712 7703-7703/com.package.name V/TokenCache: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13 - b836beb8-c8c4-4027-9dc3-4c9b795e7a26] Retrieve users with the given client id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Line 374: 11-26 21:31:13.734 7703-7703/com.package.name V/TokenCache: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13 - b836beb8-c8c4-4027-9dc3-4c9b795e7a26] Retrieve all the refresh tokens for given client id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx; Returned refresh token number is 1
Line 375: 11-26 21:31:13.735 7703-7703/com.package.name I/TAGAzureUtils: initializeMSAL:getAuthSilentCallback
Line 376: 11-26 21:31:13.735 7703-7703/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13] Passed in authority string is a b2c authority, create a new b2c authority instance.
Line 377: 11-26 21:31:13.735 7703-7703/com.package.name I/PublicClientApplication: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Preparing a new silent request
Line 378: 11-26 21:31:13.740 7703-7806/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13] Passed in authority string is a b2c authority, create a new b2c authority instance.
Line 379: 11-26 21:31:13.740 7703-7806/com.package.name V/TokenCache: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Access token item found in the cache is already expired.
Line 381: 11-26 21:31:13.753 7703-7806/com.package.name V/TokenCache: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Retrieve refresh tokens for the given cache key
Line 382: 11-26 21:31:13.754 7703-7806/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Perform authority validation and tenant discovery.
Line 383: 11-26 21:31:13.769 7703-7806/com.package.name I/Authority: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Authority has already been resolved.
Line 384: 11-26 21:31:13.773 7703-7806/com.package.name V/HttpRequest: MSAL 0.1.1 Android 23 [2017-11-26 16:01:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Sending Http Post request.
Line 395: 11-26 21:34:05.899 7703-7806/com.package.name V/HttpRequest: MSAL 0.1.1 Android 23 [2017-11-26 16:04:05 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Request timeout with SocketTimeoutException, will retry one more time.
Line 396: 11-26 21:36:13.903 7703-7806/com.package.name E/BaseRequest: MSAL 0.1.1 Android 23 [2017-11-26 16:06:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Token request failed with error: Read error: ssl=0x7f190491b880: I/O error during system call, Connection reset by peer javax.net.ssl.SSLException: Read error: ssl=0x7f190491b880: I/O error during system call, Connection reset by peer
Line 425: 11-26 21:36:13.904 7703-7806/com.package.name E/BaseRequest: MSAL 0.1.1 Android 23 [2017-11-26 16:06:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Error occurred during authentication. com.microsoft.identity.client.MsalClientException: Auth failed with the error Read error: ssl=0x7f190491b880: I/O error during system call, Connection reset by peer
Line 425: 11-26 21:36:13.904 7703-7806/com.package.name E/BaseRequest: MSAL 0.1.1 Android 23 [2017-11-26 16:06:13 - 5b62dea7-d206-49a7-aec0-375c8c6bc76c] Error occurred during authentication. com.microsoft.identity.client.MsalClientException: Auth failed with the error Read error: ssl=0x7f190491b880: I/O error during system call, Connection reset by peer
Line 461: 11-26 21:36:13.927 7703-7703/com.package.name I/TAGAzureUtils: getAuthSilentCallback Authentication failed: com.microsoft.identity.client.MsalClientException: Auth failed with the error Read error: ssl=0x7f190491b880: I/O error during system call, Connection reset by peer

MSAL B2C Authorization on Android

I've sucessfully signed in using "Azure AD B2C" on my android app. But I am not able access my asp.net core web api using the bearer token. The api is returning 401 "UnAuthorized error".

I am able to access the same api from swagger UI and Postman.

I tried to access the api from postman using bearer token received on my mobile. The api returned with the
Bearer error="invalid_token", error_description="The signature key was not found".
MSAL Version: 0.2+ and 0.3+
Any help is greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.