Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting access token #69

Open
timduncan-innowell opened this issue Oct 7, 2022 · 7 comments
Open

Not getting access token #69

timduncan-innowell opened this issue Oct 7, 2022 · 7 comments

Comments

@timduncan-innowell
Copy link

Hi,

After downloading the b2c-sample application and making config changes for my B2C tenant, I cannot get an access token back from getTokensAsync().

Here is my config:

<AuthProvider
         tenant="myapp"
         appId="<appId>"
         loginPolicy="B2C_1A_signin"
         passwordResetPolicy="B2C_1A_PASSWORD_RESET"
         profileEditPolicy="B2C_1_ProfleEdit"
         redirectURI="msauth://com.myapp/<signature_hash>"
>

I correctly get the B2C hosted signin page after clicking the LOGIN button. After entering a correct user name and password the Protected page displays "Could not authenticate".

What I do get from getTokensAsync() is:

{
  "access": "", 
  "error": null, 
  "expiresOn": 0, 
  "id": "", 
  "isAuthentic": false, 
  "url": "msauth://com.myapp/<signature_hash>?code=eyJraWQiOiIxVG9LRlVnM1lVNE9ET1lJbz..." 
}

The url seems to be the first part of the authorization code flow and afaik the package should be exchanging the authorization code for access & id tokens. The exchange does not seem to take place.

Have I done something wrong to stop the authorization code from being processed by the package and used in a token exchange?

Any help appreciated.

@timduncan-innowell timduncan-innowell changed the title No getting access token Not getting access token Oct 7, 2022
@harika-nammi
Copy link

hi @timduncan-innowell, i am also facing the same issue. Did you fix this?

@MuhammadSaadTabani
Copy link

Facing the same issue, I ask from community developers to kindly help with the solution. Thank you

@GSingh01
Copy link
Owner

GSingh01 commented Oct 9, 2022

@timduncan-innowell to me it looks like you are not being redirected to correct link for your app. Can you please put a breakpoint or console.log at

redirectURI={Linking.createURL("redirect")}
to read the value of Linking.createURL("redirect") and this is what you need to put in Azure ad b2c redirect url config for dev env.

Note: In prod, above will be different and will depend upon on schema in app config. More about it here: https://docs.expo.dev/versions/latest/sdk/linking/#linkingcreateurlpath-namedparameters

@MuhammadSaadTabani
Copy link

MuhammadSaadTabani commented Oct 9, 2022

Everything is working correctly, we are able to signin, but not getting access token. we are getting error:null and isAuthentic false.

@GSingh01
Copy link
Owner

GSingh01 commented Oct 9, 2022

@MuhammadSaadTabani there are 2 parts to it

  1. Making request to load Login screen
  2. Loading the application and authenticating after receiving redirect from ad b2c

When you refer everything is working my guess is you are referring to number 1 but unless number 2 is done you wont be authenticated.

To make sure you can put a breakpoint at redirect route and double check if it ever gets hit, if not check my initial comment. If it gets hit and you still dont see it working then please provide more info what the error code etc you are getting.

@MuhammadSaadTabani
Copy link

Yeah I am facing the following issues, kindly have a look at.

  1. when I am using Liking.createURI(''), I am getting the following response and couldn't see the login page from azure auth.
Object {
    access: "",
    error: "dismiss",
    expiresOn: 0,
    id: "",
    isAuthentic: false,
    url: ""
}

  1. When I am passing redirect uri direct string to redirectURI prop, I am able to see the login page and easily sign in to the application, but I am not getting access-token in the repsonse, the error is null by the way and isAuthentic is false, following is the response after login to the app
access: "",
error: null,
expiresOn: 0,
id: "",
isAuthentic: false,
url: msauth://someurl...

Auth Provider Configuration

<AuthProvider
        tenant={'<app-tenant>'}
        appId={'<my-app-id>'}
        loginPolicy="<login-policy>"
        passwordResetPolicy="<password-reset-policy>"
        scope={['openid', 'offline_access' ]}
        redirectURI={Linking.createURL('redirect-uri')}
>

@timduncan-innowell
Copy link
Author

timduncan-innowell commented Oct 10, 2022

@GSingh01 ,

Thanks for responding.

My current redirectURI msauth://com.myapp/<signature_hash> was configured from adding an Android platform (other options are Web, Single-page application, iOS / macOS, Mobile and desktop applications). Is Android the right platform for a React Native application?

Now, looking at the expo Linking documentation as you suggested I see this example value when running in dev environment:

Expo Client (dev): exp://128.0.0.1:19000/--/path

My understanding from your response is that I should change my redirectURI in the portal to be exp://128.0.0.1:19000/--/redirect, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants