1

I'm currently trying to do login from azure ad using :

react-native-azure-auth

Using this code :

      let tokens = await this.azureAuth.webAuth.authorize({ scope: 'offline_access profile User.ReadBasic.All Mail.Read' ,})

now it works fine only thing is I pass in scope "offline_access" and set it in the portal but in the response I don't get the refresh token and the scope field is missing offline_access ,

this is the example:

{"clientId":"69ab--04ccfbf","rawIdToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsxNDV0c2kwX2YwWndQYmh1WGlIMWpQ2diNUZnWHhUZVkiLCJ0aWTIzOS0zYjcxLTRmZjEtODk0Ny1mODZkGkiOiIzRlR1RkVlbG1raU9IUEVWbkNkT0FBIiwidmVyIjoiMi4wIn0.qQNLG2-kJ1CXIn8B4P8GUGimtT9WAiv5AaWhwl-Po_F14Oh8ZfAWTjaI8SQrnHfoHdbZY5_3nwjRT8Fz283Xy1bBKsgRCB75p936oO4ggPt4Mdhngzm3-xxRVvq8ysECaPlcQUFN9d6st4arly8umRypzyE6w","userId":"[email protected]","userName":"My name","tenantId":"2b555239-3b51-4f33-8944-f81111111e0","idTokenExpireOn":1594309415000,"accessToken":"eyJ0eXAiYS0wNDgwYTIwY2NmYmYiLCJhcHBpZGFjciI6IjAiLCJmYW1pbHlfbmFtZSI6IlR3aW5hIiwiZ2l2ZW5fbmFtZSI6Illhbml2IiwiaXBhZGRyIjoiNxMC4xNDkiLCJuYW1lIjoiWWFuaXYgVHdpbmEiLCJvaWQiOiJhNTViMjQyMy00MGZiLTRkYjQtODk0Mi02Zjg5OTBjYjE0ZmGF0ZiI6IjEiLCJwdWlkIjoiMTAwMzIwMDA4RkI1MDQ4NyIsInNjcCI6Ik1haWwuUmVhZCBvcGVuaWQgcHJvZmlsZSBVc2VyLlci5SZWFkQmFzaWMuQWxsIGVtYWlsIiwic2lnbmluX3N0YXRlIjpbImttc2kiXSwic3ViIjoiZmc5WXdIMDMwc3RRUkMzV19NMDhiRXFfRW5BeTc0ZGg4RWpScyIsInRlbmFudF9yZWdpb25fc2NvcGUiOiJFVSIsInRpZCI6IjJiZTJhMjM5LTNiNzEtNG3LWY4NmQ1OWUxNjZlMCIsInVuaXF1ZV9uYW1lIjoiWVR3aW5hQGlhaS5jby5pbCIsInVwbiI6IllUd2luYUBpYWkuY28uOiIzRlR1RkVlbG1raU9IUEVWbkNkT0FBIiwidmVyIjoiMS4wIiwieG1zX3N0Ijp7InN1YiI6IlZzLUwxNDV0c2kwX2YwWndQYmh1WGlIMWpQYTZoaGhiN2diNUZnWHhUZVkifSwieG1zX3RjZHQiOjE0NTE1NDMyNTl9.J9WGrG34tAs9zWF3hb5cfclWVyDSwbr082cMj1psaTqGf8SRl2Ji-ABc4mvD8AGo4nnLiH69J0M5oe9pi2041nymfqu6w_QZsg7QqPG24XnZ17SrBNOj8pyBI4i6dWL8QQM-k2cLGesKVl33h1qCo4IvKhzZFdxf6-NRIXsaP8-I-4oDCZD1n7vpSliJ5HSsp5Y3MhpF6IEzVgo4Drh2ZCwYuKLiWrEu6jG_kmXEmyOf0Fw"
,**"scope":{"scopeStr":"email mail.read user.read user.readbasic.all","scope":["email","mail.read","user.read","user.readbasic.all"]},**"expireOn":1594309417216}

Any ideas what i'm missing ?

7
  • 1
    Did you do every steps in this npmjs.com/package/react-native-azure-auth#app-registration ? And the code here can refresh an expired token, did it meet your requirement? Because the refresh token is used to obtain new access/refresh token pairs when the current access token expires. Commented Jul 10, 2020 at 2:02
  • 1
    You may need to use it, the code you used uses the /authorize endpoint, as I know, you could not get refresh token from it. Commented Jul 10, 2020 at 6:52
  • 1
    In the comment of the code Try to get cached token or refresh an expired ones, it can refresh an expired token, it means you don't need the refresh token, because the refresh token is used to do that. Commented Jul 13, 2020 at 1:13
  • 1
    very useful as it was the correct answer , set it as an answer so i'll mark it as true , thanks a lot ! Commented Jul 15, 2020 at 6:41
  • 1
    I add it as the answer. Commented Jul 15, 2020 at 6:51

1 Answer 1

2

You could use the code below in this link, as mentioned in the comment, it can get cached token or refresh an expired ones. No need to get the refresh token, because the refresh token is used to obtain new access/refresh token pairs when the current access token expires.

 try {
        // Try to get cached token or refresh an expired ones
        let tokens = await azureAuth.auth.acquireTokenSilent({scope: 'Mail.Read', userId: this.state.userId})
        if (!tokens) {
            // No cached tokens or the requested scope defines new not yet consented permissions
            // Open a window for user interaction
            tokens = await azureAuth.webAuth.authorize({scope: 'Mail.Read'})
        }
        let mails = await azureAuth.auth.msGraphRequest({token: tokens.accessToken, path: '/me/mailFolders/Inbox/messages'})
    } catch (error) {
      console.log(error)
    } 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.