vmurin / react-native-azure-auth

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

Not getting a refresh token #147

Closed jeroenvanhattem closed 2 years ago

jeroenvanhattem commented 2 years ago
let tokens = await azureAuth.webAuth.authorize({ scope: 'offline_access User.Read Calendars.Read Calendars.Read.Shared', prompt: 'consent', }).then((res: any) => {
        return res
      })

I use this code to authenticate a user. I get an accessToken, rawIdToken and other information returned. I do however not receive a refresh token. The scopes returned by this response do also not include the offline_access scope.

Am I missing something?

vmurin commented 2 years ago

offline_access is added by default. try to replace it with openid

Look an example in the sample app

jeroenvanhattem commented 2 years ago

@vmurin I have tried the sample app, but it's also not giving me a refresh token. Is there a specific function I need to call to receive it?

vmurin commented 2 years ago

Ahh, you are right! There was already same question. Look at the issue #67

jeroenvanhattem commented 2 years ago

@vmurin I need the refresh token in order to send it to my server. My server handles Microsoft Graph stuff to allow for multiplatform (mobile and web) use. Are there future plans for a getRefreshToken function? That'd be really great!

vmurin commented 2 years ago

You can easily access refresh token like this after login (i.e. authorize(...) function successfully completed )

console.log('Refresh token:', await azureAuth.auth.cache.getRefreshToken(tokens.userId));

See sample App login example

jeroenvanhattem commented 2 years ago

It works. Amazing. Thank you so much for your very quick responses!