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

Client SDK to request a Beams Token from your backend server #97

Open
ddhanak opened this issue Jul 27, 2021 · 6 comments
Open

Client SDK to request a Beams Token from your backend server #97

ddhanak opened this issue Jul 27, 2021 · 6 comments
Labels
enhancement New feature or request hacktoberfest

Comments

@ddhanak
Copy link

ddhanak commented Jul 27, 2021

Allow passing in the beams token when setting userId (instead of fetching from tokenProvider).

https://github.com/pusher/push-notifications-web/blob/master/src/push-notifications.js#L328

Use case: we have implemented our own logic to fetch the beams token (and we do not want to use the TokenProvider class that sends a request for us through the SDK).

@benw-pusher benw-pusher added the enhancement New feature or request label Jul 28, 2021
@ddhanak
Copy link
Author

ddhanak commented Aug 16, 2021

@benw-pusher hi ben, is it possible to know if this will be prioritized or not?

@benw-pusher
Copy link

I have shared the feedback internally but at this time we cannot commit to a release.

@ddhanak
Copy link
Author

ddhanak commented Sep 12, 2022

@benw-pusher hi any news on this? it has been more than a year now.

@benw-pusher
Copy link

Unfortunately, at this time we don't have this work scheduled.

@daniel-shuy
Copy link
Contributor

Actually, this is already possible.

Client.setUserId() takes in an interface (ITokenProvider):

setUserId(userId: string, tokenProvider: ITokenProvider): Promise<undefined>;

export interface ITokenProvider {
fetchToken(userId: string): Promise<TokenProviderResponse>;
}

export interface TokenProviderResponse {
token: string;
}

You'll just need to create your own ITokenProvider implementation that returns the token immediately, e.g.

client.setUserId(userId, {
  fetchToken: () => Promise.resolve({ token }),
});

@lukepearce
Copy link

I have tried multiple versions of the custom ITokenProvider approach, and it's working locally (I can see "Device paired with User" in the Pusher debug console) but when it's deployed to prod, I get Error: Unexpected status code 401: Unauthorized, Invalid JWT signature.

The token is being returned by my server and when decoded, it is the same shape as it is locally.

Any idea what might be happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest
Projects
None yet
Development

No branches or pull requests

5 participants