-
Notifications
You must be signed in to change notification settings - Fork 115
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
Azure B2C #91
Comments
Hi, |
Thanks, it works on the web when I clear the accessTokenEndpoint. I now have the following config: appId: "xxxxxx-xxxx-xxxxx-xxx-xxxxxxxx",
authorizationBaseUrl: "https://tenant.b2clogin.com/tfp/tenantb2c.onmicrosoft.com/B2C_1_SignUpAndSignIn/oauth2/v2.0/authorize",
accessTokenEndpoint: "",
scope: "openid offline_access https://tenantb2c.onmicrosoft.com/capacitor-api/demo.read",
responseType: "token",
web: {
redirectUrl: "http://localhost:8100/auth",
},
android: {
redirectUrl: "msalxxxxxxx-xxxxx-xxx-xxxx-xxxxxxxx://auth"
},
ios: {
redirectUrl: "msauth.com.xxxxx://auth",
resourceUrl: "https://graph.microsoft.com/"
} I now get the following errors when redirected back to the apps: Android: iOS: In string.xml: info.plist: Does anyone have any idea what I should change? |
A colleague of mine got IOS working. I haven't got Android working yet but try this config for IOS |
It worked on ios with your config, thanks. Still the same error on Android. I'll let you know if I figure it out. |
You have to play with those options. I could not reproduce the issue myself but added these params so developers have some options to work around it.
|
I made it work on Android as well. I created a new Custom redirect URI on my b2c app with the following structure: "com.tenant.app://oauth/auth". Then added "handleResultOnNewIntent: true" in the config. |
Thanks, I have used pixel 2 Android version 9 & 10 for testing
The control gets redirected to my app but Plugins.OAuth2Client.authenticate(this.oauth2Options) callback is not hit. If I use
is my configuration |
Try switching your scheme and host.
|
Thanks for helping each other. I guess this task is now ready to be closed? If you could be so nice to post a full config for Azure B2C I'll add it as a example to the readme for others having the same provider. |
Almost ready to be closed...so I've followed the steps outlined by these amazing developers in this thread and I finally get the popup, signup/signin and all is wonderful....until.....I either finish signing up or finish signing in and I'm getting the following in my console: It never appears to hit the "then" which I have starting with a log: but goes right to the catch. What am I missing? Here's my config: |
Make sure your Azure App Config is setup correctly with allowImplicitFlow: true and Grant admin consent for your permissions. Here's my config for B2C:
|
@fredbjork - Thanks for replying. It looks as though I have the allow implicit flow set, but unsure about the Grant Admin consent would be located on the Azure ADB2C blade. I'm assuming that is what's tied to the last scope item you have on your reply? |
@fredbjork - ok I got it, after granting those permissions I was still getting an error. Turns out if I had paid closer attention to your config, I would have noticed you didn't have a few of the items I had in mine. Once I removed those items and made it match yours, it worked like a charm. Thanks again!! |
I added the config to the README. @fredbjork thx for sharing. |
@fredbjork did you face the issue I have posted #96 ? |
You said above:
How did you add this custom redirect URI. When I add a new URI for the Android Platform, it is locked down. The redirect url always begins with msauth://. |
@NishaBhat did you ever get your android version working. I am having the same issue that you described. My config is identical to what you have with the msauth:// and I am getting the exact same behavior you describe where control returns to my app but callback is not hit because of the ERR_ANDROID_NO_INTENT. @fredbjork stated that he solved it by adding a custom redirect URI on his b2c app as I mentioned just above, but I see no way of adding a custom redirect url as he describes. I do have it working on ios. I have tried all of the suggestions in this chain but still can't get it to work. @moberwasserlechner does the plugin handle the msauth:// android redirectUrl format? In the azure portal for android the RedirectUrl has to be in the following format: So in my config it has: And in my AndroidManifest.xml I have: Again I get the same exact bahavior as @NishaBhat described. Thanks, |
Hi Billy,
|
Hi @NishaBhat, I changed my redirect uri as you suggested in the android config section but no matter what, when I run the app I get the error in the screen shot below. Couple of questions:
Do you see anything I have misconfigured? I don't see how I can get past the error below using the redirectUrl you suggested, since it is not registered that way in Azure. Thanks, I really appreciate the help. |
Hmm, I might know what's wrong. Have you added Yes, I do have msauth://com.domain.app/SIGNATURE_HASH as redirect_url in Azure In AndroidManifest.xml I have
In build.gradel I have |
Hi @NishaBhat I really appreciate your help. I think I am close. I did what you said and setup the com.domain.app://oauth/auth in azure where you said. That did partially work. I now get to the login with no problems and then once I login I am redirected back to my android app. However I get the following error:
Here is my entire capacitor-oauth2 config:
I debugged the android code to see what is happening and this is what I found: The handleAuthorizationRequestActivity gets call 2 times because I have handleResultOnNewIntent and handleResultOnActivityResult set to true. The first time handleAuthorizationRequestActivity is called, the intent is null, which I think is ok according to the comments. This causes it to call savedCall.reject(ERR_ANDROID_RESULT_NULL) which is defined as ERR_ANDROID_NO_INTENT. The second time handleAuthorizationRequestActivity is called, the intent has a value. It then tries to create an AuthorizationResponse from the intent by checking to see if the extras on the intent has an extra with the following key: net.openid.appauth.AuthorizationResponse defined by the constant EXTRA_RESPONSE. An Extra with that key is not found so it returns null. Next it checks to see if there is an error on the Intent by checking to see if there is an Extra with the key: net.openid.appauth.AuthorizationException defined by EXTRA_EXCEPTION. The extra does not exist so it returns null for the error. Since both of these are null, when it next calls this.authState.update(authorizationResponse, error) an exception is thrown stating that one of them should be non-null. Finally it calls savedCall.reject(ERR_GENERAL, e) and control is returned back to the Android app with error(s). In the dev console I see the 2 errors. The first error, I assume, is from when the intent is null on the first call to handleAuthorizationRequestActivity. The error is ERR_ANDROID_NO_INTENT which seems to be a handled exception and the second which is an unhandled exception ERR_GENERAL created when it could not find the authorizationresult and no error in the extras of the intent. |
@billyjacobs2014 Hey could you fix the problem with the Intent, I am really stuck at this point. I debug the app and I see what you told. Did you find a solution? |
HI @NishaBhat @billyjacobs2014 @moberwasserlechner @CarlosDez23 "The control gets redirected to my app but Plugins.OAuth2Client.authenticate(this.oauth2Options) callback is not hit" Facing the same issue. could you guys help me fix it. TIA |
Description
I'm trying to use this plugin with Azure B2C in my Angular project, but haven't been able to make it work.
If anyone here has done this already, some help would be much appreciated.
I get sent to the Azure Policy where I can sign in, but on redirect I get 2 types of errors:
If I set responseType: "code token":
ERR_GENERAL: See client logs. It might be CORS. Status text:
"Access to XMLHttpRequest at 'https://{tenant}b2c.b2clogin.com/{tenant}b2c.onmicrosoft.com/oauth2/v2.0/token' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
If I set responseType: "token":
"OAuth rejected Error: ERR_NO_AUTHORIZATION_CODE"
Capacitor version:
Library version:
OAuth Provider:
Your Plugin Configuration
Thanks!
The text was updated successfully, but these errors were encountered: