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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 [firebae_auth] custom claims is null on windows desktop #11949

Closed
floyd-lewis opened this issue Nov 26, 2023 · 8 comments
Closed

馃悰 [firebae_auth] custom claims is null on windows desktop #11949

floyd-lewis opened this issue Nov 26, 2023 · 8 comments
Assignees
Labels
blocked: firebase-sdk platform: windows Issues / PRs which are specifically for Windows. plugin: auth resolution: duplicate This issue or pull request already exists type: bug Something isn't working

Comments

@floyd-lewis
Copy link

floyd-lewis commented Nov 26, 2023

Bug report

Describe the bug
A clear and concise description of what the bug is.
Custom claims was set for a user with a role using admin sdk in javascript.

When logging into the app On Web and Android, when the user logs in the app gets the custom claim. On windows the claims is null.

pubspec.yaml
firebase_core: ^2.23.0
cloud_firestore: ^4.13.2
firebase_auth: ^4.14.1
cloud_functions: ^4.5.5
firebase_storage: ^11.3.1

Using google_sign_in_dartio for windows

@floyd-lewis floyd-lewis added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Nov 26, 2023
@floyd-lewis
Copy link
Author

Some more information
I get the claims data by calling getIdTokenResult. The claims is null on windows desktop. However if I call getTokenData and then decode using jwt_decoder package it has the claims data. This works on android too.

@darshankawar darshankawar added the triage Issue is currently being triaged. label Nov 27, 2023
@darshankawar
Copy link

@floyd-lewis Thanks for the report.
Can you elaborate on how are you setting the custom claims and then trying to retrieve it ? A code sample will also be helpful so that we can address it properly.

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Nov 27, 2023
@floyd-lewis
Copy link
Author

@floyd-lewis Thanks for the report. Can you elaborate on how are you setting the custom claims and then trying to retrieve it ? A code sample will also be helpful so that we can address it properly.

const email = 'xxxx@gmail.com';
admin.auth().getUserByEmail(email).then((user) => {
const uid = user.uid;

admin.auth().setCustomUserClaims(user.uid, {
    'role': 'CURATOR'
});

admin
    .auth()
    .getUser(uid)
    .then((userRecord) => {
        console.log('uid ' + uid);
        console.log(userRecord.customClaims);
    });

});

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Nov 27, 2023
@floyd-lewis
Copy link
Author

For retreival i modifies the code as below for it to work in flutter, Earlier I was using getIdTokenResult, which was returning a nulllfor claims. Please note that it only does not work for windows desktop

String? tokenStr =
await firebase_auth.FirebaseAuth.instance.currentUser!.getIdToken();

  Map<String, dynamic> decodedToken = JwtDecoder.decode(tokenStr!);
  var roleName = decodedToken['role'] ?? Role.LEARNER.name;

@floyd-lewis
Copy link
Author

Old code which did not work on windows desktop
firebase_auth.IdTokenResult? idTokenResult = await firebase_auth
.FirebaseAuth.instance.currentUser
?.getIdTokenResult();

  var roleName = idTokenResult?.claims?['role'] ?? Role.LEARNER.name;

@darshankawar
Copy link

Thanks for the update. Upon verifying on windows machine, getting the same result as reported.

/cc @Lyokone

@darshankawar darshankawar added plugin: auth platform: windows Issues / PRs which are specifically for Windows. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels Nov 28, 2023
@Lyokone Lyokone self-assigned this Nov 28, 2023
@Lyokone
Copy link
Contributor

Lyokone commented Nov 28, 2023

Opened an issue on the C++ repository for support: firebase/firebase-cpp-sdk#1494

@TarekkMA
Copy link
Contributor

TarekkMA commented Apr 23, 2024

Will close this in favor of #11768.

@TarekkMA TarekkMA added the resolution: duplicate This issue or pull request already exists label Apr 23, 2024
@firebase firebase locked and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: firebase-sdk platform: windows Issues / PRs which are specifically for Windows. plugin: auth resolution: duplicate This issue or pull request already exists type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants