firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.67k stars 3.97k forks source link

firebase_auth Login with Microsoft Oauth2 not working. #11295

Closed parth22 closed 2 months ago

parth22 commented 1 year ago

I'm doing login with Microsoft in my Flutter app using firebase_auth. I have followed each step written in Firebase's official documentation. But still, I'm getting the below error when I try to log in with my Microsoft account.

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/invalid-credential] Error getting access token from microsoft.com, OAuth2 redirect uri is: https://flutterdev-58b4c.firebaseapp.com/__/auth/handler, response: OAuth2TokenResponse{params: error=invalid_request&error_description=AADSTS90023:%20Public%20clients%20can't%20send%20a%20client%20secret.%0D%0ATrace%20ID:%20f0f59fc3-915a-4772-9bbb-bcdc4242b200%0D%0ACorrelation%20ID:%205b0dd92e-1095-40ec-9a53-92e373a413c1%0D%0ATimestamp:%202023-07-14%2007:59:48Z&timestamp=2023-07-14%2007:59:48Z&trace_id=f0f59fc3-915a-4772-9bbb-bcdc4242b200&correlation_id=5b0dd92e-1095-40ec-9a53-92e373a413c1, httpMetadata: HttpMetadata{status=400, cachePolicy=NO_CACHE, cacheDurationJava=null, cacheImmutable=false, staleWhileRevalidate=null, filename=null, lastModified=null, retryAfter=null, crossOriginEmbedderPolicy=null, crossOriginOpenerPolicy=null, crossOriginResourcePolicy=null, headers=HTTP/1.1 200 OK

The error itself says that Public clients can't send a client secret. So, I have tried to remove the client's secret value from my Firebase project config. But, this field is mandatory. I'm also attaching the configuration screenshots of my Firebase and Azure portals.

Screenshot 2023-07-15 at 1 18 25 PM Screenshot 2023-07-15 at 1 19 17 PM Screenshot 2023-07-15 at 1 19 40 PM Screenshot 2023-07-15 at 1 50 35 PM
danagbemava-nc commented 1 year ago

Hi @parth22, can you share the code sample you use to call Microsoft?

Your error message indicates that you're sending something which public client should not be sending

parth22 commented 1 year ago

@danagbemava-nc This is the code I'm using.


final FirebaseAuth auth = FirebaseAuth.instance;
    var microsoftProvider = MicrosoftAuthProvider();
    microsoftProvider.addScope('mail.read');

    UserCredential token = await auth.signInWithProvider(microsoftProvider);
danagbemava-nc commented 1 year ago

Hi @parth22, what platform are you targeting? You may need to switch the method being called based on the platform you're testing. See https://firebase.google.com/docs/auth/flutter/federated-auth#ios+_1

parth22 commented 1 year ago

@danagbemava-nc I'm targeting the Android and iOS platforms.

danagbemava-nc commented 1 year ago

Hi @parth22, one final thing, can you try using OAuthProvider directly, instead of MicrosoftAuthProvider to see if it works for you? The provider id would be "microsoft.com".

parth22 commented 1 year ago

@danagbemava-nc Sure, let me try.

parth22 commented 1 year ago

@danagbemava-nc I have tried as you say. Below is the sample code.

final FirebaseAuth auth = FirebaseAuth.instance;
    OAuthProvider oAuthProvider = OAuthProvider('microsoft.com');
    UserCredential userCredential =
        await auth.signInWithProvider(oAuthProvider);

Ended with the same error.

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/invalid-credential] Error getting access token from microsoft.com, OAuth2 redirect uri is: https://mind-bank-ai.firebaseapp.com/__/auth/handler, response: OAuth2TokenResponse{params: error=invalid_request&error_description=AADSTS90023:%20Public%20clients%20can't%20send%20a%20client%20secret.%0D%0ATrace%20ID:%204e0e2c67-c996-482b-9e2a-9b498bd45400%0D%0ACorrelation%20ID:%20e988768f-8cb8-4515-a973-d5728b25e0ab%0D%0ATimestamp:%202023-07-19%2011:27:26Z&timestamp=2023-07-19%2011:27:26Z&trace_id=4e0e2c67-c996-482b-9e2a-9b498bd45400&correlation_id=e988768f-8cb8-4515-a973-d5728b25e0ab, httpMetadata: HttpMetadata{status=400, cachePolicy=NO_CACHE, cacheDurationJava=null, cacheImmutable=false, staleWhileRevalidate=null, filename=null, lastModified=null, retryAfter=null, crossOriginEmbedderPolicy=null, crossOriginOpenerPolicy=null, crossOriginResourcePolicy=null, headers=HTTP/1.1 200 OK
danagbemava-nc commented 1 year ago

Thanks for the info, labeling for the teams attention

CanDuru4 commented 1 year ago

Hi, did you able to solve this problem? I am facing with the same issue.

parth22 commented 1 year ago

No, Even after trying everything. At last, my client changes the requirements.

CanDuru4 commented 1 year ago

I just figured it out. From the Azure AD portal, your client should authorize an access token (from "Implicit grant and hybrid flows").

parth22 commented 1 year ago

Great. I will check it out. And, update you here.

xanscale commented 1 year ago

i have same problem using Android native integration

com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The supplied auth credential is malformed or has expired. [ Error getting access token from microsoft.com, OAuth2 redirect uri is: https://advisory-certificates.firebaseapp.com/__/auth/handler, response: OAuth2TokenResponse{params: error=invalid_request&error_description=AADSTS90023:%20Public%20clients%20can't%20send%20a%20client%20secret.%0D%0ATrace%20ID:%207375c6a1-bbdf-4e8c-a382-3992a0f31400%0D%0ACorrelation%20ID:%20fc522470-8f35-4fe4-9e7c-8e9fa9c33af9%0D%0ATimestamp:%202023-09-12%2023:13:25Z&timestamp=2023-09-12%2023:13:25Z&trace_id=7375c6a1-bbdf-4e8c-a382-3992a0f31400&correlation_id=fc522470-8f35-4fe4-9e7c-8e9fa9c33af9, httpMetadata: HttpMetadata{status=400, cachePolicy=NO_CACHE, cacheDurationJava=null, cacheImmutable=false, staleWhileRevalidate=null, filename=null, lastModified=null, retryAfter=null, crossOriginEmbedderPolicy=null, crossOriginOpenerPolicy=null, crossOriginResourcePolicy=null, headers=HTTP/1.1 200 OK

Lyokone commented 3 months ago

Hello, a lot have changed since this issue, are you still reproducing this?

google-oss-bot commented 3 months ago

Hey @parth22. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 2 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@parth22 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.