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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication issues #73

Closed
Dragon863 opened this issue Sep 3, 2023 · 5 comments · Fixed by #78
Closed

Authentication issues #73

Dragon863 opened this issue Sep 3, 2023 · 5 comments · Fixed by #78
Assignees

Comments

@Dragon863
Copy link

Hi there! Thanks for the useful package, unfortunately I'm running into two issues. Firstly, the timestamps for the session expiry seem to be reported incorrectly (at some point in 1970), I believe this is because in session.dart fromMillisecondsSinceEpoch is being called on the decoded token which stores the token in seconds since epoch. Whilst this can be worked around by changing the arguments to (token['exp'] as int) * 1000 in every line where this function is called in the file, I am still getting the message "Auth token invalid" when using any function with the session object (for example addFriends). I'm not sure if this is an issue with the package or the server I'm running, but I thought it could be relevant or maybe caused by the first issue.

I used the official docs and logged using email and then attempted to add a friend to the account using the following:

session = await client.authenticateEmail(
    username: "example",
    password: "example",
);
print(session.expiresAt);
await client.addFriends(
    usernames: ["test"],
    session: session,
);

This gives the following output:

flutter: 1970-01-20 15:29:28.873
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: gRPC Error (code: 16, codeName: UNAUTHENTICATED, message: Auth token invalid, details: [], rawResponse: null, trailers: {})

After applying the fix I mentioned above the session is reported as expiring at the correct date, but the second error still occurs.

I am using flutter 3.13.0 and the latest version of this ibrary on pub.dev, and the latest docker image of nakama. Thank you in advance!

@obrunsmann obrunsmann self-assigned this Sep 23, 2023
@obrunsmann
Copy link
Contributor

Thank you @Dragon863 for reporting. I am just back from vacation and checking in your issue shortly.

@LucaJeevanjee
Copy link

Hi I am getting the same! Auth token always invalid. Any progress?

@taciomedeiros
Copy link

taciomedeiros commented Nov 12, 2023

This error is occuring because there is no token sended by the client. There is an options parameter in the methods that make GRPC calls and a method to prepare session as token

Captura de Tela 2023-11-12 às 09 03 38

Just add this line on the methods that you want

@ilmalte
Copy link
Collaborator

ilmalte commented Nov 25, 2023

Bump :)

edit: I was facing the same issue while authenticating and using the token for creating a group.
I confirm @taciomedeiros solution helped me fix this issue.

in session.dart

    expiresAt: DateTime.fromMillisecondsSinceEpoch(
        (token['exp'] as int) * 1000,
    ),
    refreshExpiresAt: DateTime.fromMillisecondsSinceEpoch(
	(refreshToken['exp'] as int) * 1000,
    ),

in nakama_grpc_client.dart

      final res = await _client.createGroup(api.CreateGroupRequest(
      name: name,
      avatarUrl: avatarUrl,
      description: description,
      langTag: langTag,
      maxCount: maxCount,
      open: open,
    ),
    options: _getSessionCallOptions(session),
  );

@obrunsmann
Copy link
Contributor

Token parsing issue and missing options fixed in next release (releasing today)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants