react-native-azure-auth icon indicating copy to clipboard operation
react-native-azure-auth copied to clipboard

How to ask Microsoft credentials on subsequent logins?

Open MarcoBrugali opened this issue 4 years ago • 10 comments

Hi all, is there a way to "clear the cache" so that on subsequent logins it asks me for my microsoft credentials in the webview? I tried "clearSession", but the next time I log in it doesn't ask me for credentials

MarcoBrugali avatar Jun 29 '21 14:06 MarcoBrugali

Hi Marco,

please check out the sample app. If I logout there and then click login again - I'm always asked for credentials! (tested on Android emulator)

vmurin avatar Jun 29 '21 14:06 vmurin

Hi, i see in the example "azureAuth.webAuth.clearSession()" but at the next login not ask me credentials (test on ios emulator and android device)

MarcoBrugali avatar Jul 02 '21 08:07 MarcoBrugali

Have you tested with sample app or with you own only?

vmurin avatar Jul 04 '21 16:07 vmurin

It happens to me too, and I think that it is related to the other issue I opened. It doesn't ask for the credentials again because the clearSession doesn't actually resolve the logout. At least not on real devices.

0xc14m1z avatar Jul 05 '21 06:07 0xc14m1z

facing same issue, tested on real and emulator both android and ios.

akshgods avatar Jul 05 '21 09:07 akshgods

@0xc14m1z @akshgods Hi Guys, I can not see your code, so please check the behaviour based on test with the sample app! Check it out, replace the client ID in the App.js and do the same test. Otherwise I don't get what am I doing wrong :))) , so that in my tests all works as intended.

vmurin avatar Jul 05 '21 11:07 vmurin

@vmurin I confirm, not even works for me requires credentials with the sample app.

this is my code, very simple:

import {isAndroid} from "../utils/dimension";

const azureAuth = new AzureAuth({
  clientId: '9ebaf856-026d-49bd-b26c-a026667b71e7',
  redirectUri: isAndroid ? 'msauth://com.gsm.buildings/Bfqg%2BiOTWf02SCYBvmmKK1qrtxM%3D' : 'msauth.com.gsm.buildings://auth',
  persistentCache: false,
});

export const getAzureToken = async () => {
  return await azureAuth.webAuth.authorize({scope: 'openid profile User.Read Mail.Read' })
}
export const logoutAzure = async () => {
  return await azureAuth.webAuth.clearSession({closeOnLoad: true})
}

I tried both with and without "persistCache" and "closeOnLoad"

MarcoBrugali avatar Jul 05 '21 16:07 MarcoBrugali

@vmurin I literally just cloned the sample app, changed the clientId and the bundle identifier to have the callback url to work. It doesn't log me out 😔

0xc14m1z avatar Jul 06 '21 14:07 0xc14m1z

I have just tested the sample app on the real device (Samsung S10). It works as intended. It asks me for credentials every time I click login button!!!

So my suggestion - there is something with the app registration... @0xc14m1z Could you please check it up. Please run the sample app without any changes with my Client ID: 9e124cf5-641c-4f4d-907f-937714c66e3d

vmurin avatar Jul 06 '21 19:07 vmurin

You can add prompt: 'login' in azureAuth.webAuth.authorize method. let tokens = await azureAuth.webAuth.authorize({ prompt: 'login', scope: 'openid profile User.Read offline_access Calendars.Read', });

SahilMoglix avatar Apr 12 '23 06:04 SahilMoglix