Firebase Auth returns v1 token instead of v2 when using OAuth 2.0, and adding custom scopes causes authentication failure #17088
Labels
blocked: customer-response
Waiting for customer response, e.g. more information was requested.
platform: android
Issues / PRs which are specifically for Android.
platform: ios
Issues / PRs which are specifically for iOS.
plugin: auth
type: bug
Something isn't working
Is there an existing issue for this?
Which plugins are affected?
No response
Which platforms are affected?
No response
Description
Firebase Authentication currently supports signing in using OAuth 2.0 (Microsoft OAuth, Google, etc.). However, when using Microsoft OAuth 2.0 to sign in via Firebase with signInWithProvider(), the access token returned is v1, even though my backend system requires v2 for authentication.
Additionally, when adding a custom scope (api:///MyCustomScope.Read), the authentication fails with the following error:
[firebase_auth/invalid-credential] {"error": {"code":"InvalidAuthenticationToken","message":"Access token validation failure. Invalid audience."}}
Expected Behavior:
Firebase should return a v2 token when authenticating using OAuth 2.0 since Microsoft has switched to the OAuth 2.0 endpoint (/v2.0/authorize and /v2.0/token).
Adding a custom scope (api:///MyCustomScope.Read) should not cause authentication failure and should be correctly included in the token.
Setting the authority parameter to explicitly use /v2.0/authorize should ensure the correct token version.
Actual Behavior:
Firebase returns a v1 token, which causes authentication failure with my backend since it requires a v2 token.
When retrieving a token directly from Postman or Azure OAuth, the token returned is v2, but Firebase still provides v1.
Adding the custom scope (api:///MyCustomScope.Read) results in an InvalidAuthenticationToken error, meaning the audience validation fails.
Error Message:
[firebase_auth/invalid-credential] {"error": {"code":"InvalidAuthenticationToken","message":"Access token validation failure. Invalid audience."}}
Possible Fix:
Firebase should update its OAuth 2.0 integration to support v2 tokens from Microsoft.
Allow developers to specify whether they want a v1 or v2 token when authenticating.
Investigate why custom scopes cause an InvalidAuthenticationToken error and provide a fix or guidance on properly adding API scopes.
Ensure that the authority parameter is correctly handled when set in setCustomParameters().
Environment:
Firebase Auth SDK Version: latest
Flutter Version: [your flutter version]
Platform: iOS / Android
OAuth Provider: Microsoft
Reproducing the issue
` final microsoftProvider = OAuthProvider("microsoft.com");
microsoftProvider.addScope("email");
microsoftProvider.addScope("profile");
microsoftProvider.addScope("openid");
microsoftProvider.addScope("api:///MyCustomScope.Read"); // Adding this scope causes failure
microsoftProvider.setCustomParameters({
'tenant': '',
'authority': 'https://login.microsoftonline.com//oauth2/v2.0/authorize',
});
UserCredential userCredential = await FirebaseAuth.instance.signInWithProvider(microsoftProvider);
print(userCredential.credential?.accessToken); `
Firebase Core version
2.27.0
Flutter Version
3.19.0
The text was updated successfully, but these errors were encountered: