vmurin / react-native-azure-auth

React Native library implementing Azure AD OAuth2 API
MIT License
85 stars 65 forks source link

[Android] Token not received after redirecting from login #142

Closed DipUmg closed 2 years ago

DipUmg commented 2 years ago

Hi,

I am trying to use AD FS as Identity provider with this library.

It works fine with iOS, redirects and returns token back from the login screen. However in case of Android, after redirecting from the Login screen it returns error "TypeError: Network request failed]".

I tried to catch exceptions in react-native-azure-auth/src/webauth/index.js in the following code

       const tokenResponse = await client.exchange({
            code,
            scope: scope.toString(),
            code_verifier: verifier
        })

Exception caught "TypeError: Network request failed]"

vmurin commented 2 years ago

Hi,

could you check your app config especially property android:launchMode="singleTask"

Is everything like in the README?

DipUmg commented 2 years ago

Yes, it is as per the README. with ${applicationId} replaced by my package name

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data
        android:pathPrefix="/android/callback"
        android:host="${applicationId}"
        android:scheme="${applicationId}" />
</intent-filter>
</activity>

Any idea what could be wrong or what i need to check more specifically?

DipUmg commented 2 years ago

Just to add more info, I am using a self-signed SSL certificate with my ADFS setup.

Can that be an Issue on Android? as it works perfectly fine with iOS.

vmurin commented 2 years ago

I did not get where is the self-signed SSL certificate used? You are loggin in anyway over Azure. Right?

And another question: does it works on android Emulator? And one more: are the callback URLs for iOS and Android very different?

From my side I can say - I only tested it on android (both emulator and device) and it always works as intended. Most problems I saw by other users was related to some wrong or special Azure setup - for example not enabled openid, B2C case, organisational access restrictions in Azure server, corporate firewall issues and so on...

DipUmg commented 2 years ago

Hi,

Found out the issue was indeed due to use of self-signed certificate, which for some reason was not by-passed on Android. Added a trusted SSL certificate and It worked as intended.

Thanks for your time @vmurin. and to clear your confusion, I was using 'react-native-azure-auth' not with Azure Active directory but with ADFS(Active Directory Federation services) and it requires a SSL Cert. on this ADFS server.

Cheers!

vmurin commented 2 years ago

Hi,

thank you very much for clearing the issue and posting your feedback here! It could help others with similar setup.