pusher / pusher/pusher-websocket-react-native
What should `onAuthorizer` return when authorization is denied?
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 76
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
I can't find a clear answer to this question in the documentation. In the Pusher authorization docs it says:
Unsuccessful responses from an authorization endpoint should serve a 403 Forbidden HTTP status.
Moreover, return type of onAuthorizer is Promise<PusherAuthorizerResult> which is defined as
export interface PusherAuthorizerResult {
auth?: string;
shared_secret?: string;
channel_data?: string;
}
Together this makes me think that onAuthorizer should return {} when the server responds with HTTP 403. But if I do that, then I get the following error: Client error | Invalid key in subscription auth data: '<missing_auth_param>' since the auth field is missing.
If I instead look at the usage of onAuthorizer in the Pusher class, I see this in Pusher#init:
this.addListener(
PusherEventName.ON_AUTHORIZER,
async ({ channelName, socketId }) => {
const data = await args.onAuthorizer?.(channelName, socketId);
if (data) {
await PusherWebsocketReactNative.onAuthorizer(
channelName,
socketId,
data
);
}
}
);
Here we check if the result of onAuthorizer is truthy before calling the native method. So from this I think that onAuthorizer should return a falsey value if authorization fails. But that (1) wouldn't typecheck and (2) if I return undefined then I instead get Client Error | Invalid key in subscription auth data: '<authorizer_timeout>'
So I'm at a bit of a loss as to how to implement this correctly. Should I just be handling the client errors with the onError method? Any pointers here, am I overlooking something?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the onAuthorizer contract in the Pusher class's init listener and compare it with the linked Pusher authorization response documentation. Trace how {}, undefined, and denied authorization are handled by the native method and onError. Done means the documented return and error behavior, including the missing-auth and authorizer-timeout cases, is clear and consistent with the TypeScript type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- authorization, mobile
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100