Earlybyte / aad_oauth

Flutter Azure Active Directory OAuth Package
https://pub.dev/packages/aad_oauth
MIT License
93 stars 190 forks source link

What am I doing wrong? #345

Open JacoFourie opened 1 month ago

JacoFourie commented 1 month ago

Hi.

Sorry to bug you. It is not very clear what the redirectUri should be for a mobile App. iOS and Android.

What I did was the following.

Created a app on Azure got the tenant and clientid

image

For the redirectUri I have configured the msal(clientid)://auth

When I login I get these screens. The 2FA does not show

image

image

It will set stuck at this point with the loader running at the top op the screen. The dotts scrolling across

image

If I set the redirect URI to this. without configuring it the 2FA will pop up

"https://login.microsoftonline.com/common/oauth2/nativeclient"

But then once I enter the 2FA code I get this redirect error.

image

JacoFourie commented 1 month ago

Hi. Is this library still in active use?

justoke commented 1 month ago

Hi. I believe it is active. I have been using it for over 2 years for our mobile app using the Azure B2c platform.

Here is the format I am using for the return url image

It looks like you are using Azure Active Directory, and usually the return URLS are defined under the Authentication section of your app registration.

You should have added the platform under the app registration for Android

image image

I have something like this image

justoke commented 1 month ago

I'd suggest running the Integration Assistant on your app registration, indicating you are using a mobile app and see if it can offer some insight into what might be missing

image

JacoFourie commented 1 month ago

Hi @justoke. Thanks for answering me. I am new to Azure. What is the difference between Azure B2c and Azure AD? I only want to use Azure to authenticate my company's users. At this point, I don't have access to the Azure portal. I have to ask one of our admins to make a change every time. I am developing on a Mac with iOS. I see you stated this "You should have added the platform under the app registration for Android" Does this mean iOS won't work if we have not set up Android yet? I just wanted to get the POC going to see what is required to authenticate using MS Azure. Currently, we are using Novell Directory services / LDAP. We are migrating to Azure.

justoke commented 1 month ago

Hi. You can add any platform - I just assumed you might be using Android. I use Flutter for mobile development, so I added the Mobile & Desktop applications. The point is mainly that it is the app registration where the returnURLs are defined and configured. Azure B2C and Azure AD are both directories, but Azure B2C is for Business to Customer authentication where you want to have large numbers of people interacting via a federated login and user identity management platform. That said, from the perspective of this library it is not relevant.

With your Azure AD, you still need an app registration - I'd ask the admin to give you the screenshots of the app registration, in particular from the Authentication settings and the return URLs. Most of the issues, if not all that I had using this library were all down to configuration and settings on the Azure AD. At its core, this library just makes the necessary http calls to get a token to authenticate users from the client/mobile app.

I would suggest trying to get Azure access, otherwise just sign up for a free account and do the POC that way - at least then you will be able ask the company admin to make the changes needed. It is quite a steep learning curve and I initially hired an Azure consultant to guide me on the Azure B2C, although I also use the Azure AD for the company systems. The app registration on both is the same as far as I can tell, just the configuration settings like tenantId, audienceId etc vary accordingly.

justoke commented 1 month ago

PS Looking again at the error message you have, it is saying that the redirect URLs do not match that configured for the application( this means for the App registration) - which is the same error you get it they are not configured at all. Basically there is no match, so I think that is the most likely issue you face at the moment. What you have might even be correct, just it has not been configured.