vmurin / react-native-azure-auth

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

android stuck on "continue", does nothing #216

Closed jliukai closed 3 months ago

jliukai commented 6 months ago

Problem

When I attempt to sign in, and press "continue" it does nothing.

tBUI3

Setup

const azureAuth = new AzureAuth({ clientId: Config.MICROSOFT_CLIENT_ID, redirectUri: Config.MICROSOFT_REDIRECT_URI_ANDROID })

const tokens = await azureAuth.webAuth.authorize({ scope: 'email openid profile User.Read offline_access', prompt: 'select_account' }) console.log('tokens') // <--- never gets to here

vmurin commented 6 months ago

Please check the issue #27 and give your feedback here 🙏🏻

qwert251102 commented 5 months ago

same @vmurin issue for me i have checked https://github.com/vmurin/react-native-azure-auth/issues/27 here is the intent filter`

       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />
       <data
          android:scheme="msauth"
          android:host="package-name"
          android:pathPrefix="/signature-hash"
         />
   </intent-filter>` in place of package-name i have used my real package name 

in place of signature-hash i have used my signature-hash

jliukai commented 3 months ago

same problem :( @qwert251102

I tried different variants, one at a time, Androidmanifest.xml. none worked

following https://github.com/vmurin/react-native-azure-auth/issues/27 tried variant 2,3 and 4. failed.

# Androidmanifest.xml
 <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <!-- variant 0 start from author's docs. -->
            <data
              android:pathPrefix="/android/callback"
              android:host="${applicationId}"
              android:scheme="${applicationId}" 
            />
             <!-- variant 0  end -->

            <!-- variation 1 start -->
            <data            
              android:scheme="msauth" 
              android:host="com.<my package name>" 
              android:pathPrefix="/gYxxxxxxxxxxxxxZbo" 
            />
             <!-- variation 1 end-->

             <!-- variation 2 start -->
             <data
              android:host="auth"
              android:scheme="msauth://com.myapp.prod/gYxxxxxxxxxxxxxxZbo%3D" // from android redirect
            />
              <!-- variation 2 end -->

              <!-- variation 3 start -->
             <data
              android:host="auth"
              android:scheme="msal2b9xxxxxxxxxxxxxxxxxxxx2a3://auth"  // from mobile/desktop redirect
            />
              <!-- variation 3 end -->

                 <!-- variation 4 start -->
             <data
              android:host="auth"
              android:scheme="msal2b9xxxxxxxxxxxxxxxxxxxx2a3"  // from mobile/desktop redirect
            />
              <!-- variation 4 end -->
        </intent-filter>
// react native code
 const azureAuth = new AzureAuth({ clientId, redirectUri })
    const tokens = await azureAuth.webAuth.authorize({
      scope: 'email openid profile User.Read offline_access',
      prompt: 'select_account'
    })

how i created my hash

  1. i tried both development via using debug.keystore and production from the google play store downloading deployment_cert.der
  2. from a mac, ie. using cli command: keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64 to generate the hash
  3. taking the hash in to get redirect uri
    • MS entra website > app registrations > and in the android section -> to get the redirect uri.
    • putting hash in androidmanifest, as seen above.
    • and redirecturi my react native code seen above.

entra auth setup

  1. Android section
    • has the sign hash and redirect uri
  2. mobile desktop application has the uris:

I still have problem where "continue" button doesnt do anything. im sure its something wrong with redirect url or some config around that.

as a side note, iOS microsoft sign in with this library works fine.

vmurin commented 3 months ago

Hi @jliukai

please try following:

  1. remove android as a Platform from the App registration. It is actually enough to have "Mobile and Desktop applications" 2a. Use you the variant 4 but double check the URL spelling 2b. Or Use the variant as in the documentation
  android:pathPrefix="/android/callback"
  android:host="com..prod"
  android:scheme="com..prod" 

here supposed "com..prod" is your package name and it is correctly put in the Azure App registration as the callback URI

  1. please check the value of the redirectUri variable in the code const azureAuth = new AzureAuth({ clientId, redirectUri }) It should be exactly copy-pasted from Azure URIs list

The main rule: App registration callback URI === redirectUri variable === android:scheme + :// + android:host + android:pathPrefix

jliukai commented 3 months ago

it worked!! thank you thank you!!!

 # androidManifest.xml
 <data
              android:pathPrefix="/android/callback"
              android:host="${applicationId}"
              android:scheme="${applicationId}" 
            />
vmurin commented 3 months ago

@jliukai thank you for your feedback