Skip to content

Pass Bearer token as query request option #1528

Open
@stephannielsen

Description

@stephannielsen

New Feature / Enhancement Checklist

Current Limitation

We are using JWT based authentication (parse-community/parse-server#6411) on server side together. Currently, we do not create Parse Sessions anymore as they are not needed. We are using cloud functions, which works fine with the JWT approach but one downside is that it is not easy to run the cloud function in the user context because we have no sessionToken to pass to the SDK. We could use CoreManager to set the Auth token, but it is set globally which we want to avoid in Cloud context where requests are made in multiple user contexts. If we don't reset the code properly, another request might use the token from another user...not to speak of concurrency issues in general with that approach. I proposed request interceptors as a new feature in #1449 which would tackle the same problem but now thought of a different way which would make it especially easier for cloud functions.

Feature / Enhancement Description

It is possible to pass a session token to the Parse.Query call via options:

myQuery.save(null, { sessionToken: 'abc' });

This token is added to the request as a X-Parse-Session-Token header and interpreted on server side.
The idea is now to add another option, authorizationHeader to options which is then simply added as Authoriation header to the request. Parse Server would then validate this bearer token like a usual request and use the JWT functionality.

If I am not mistaken, the change would be fairly simple and only touch RestController.js + tests.

Example Use Case

myQuery.save(null, { authorization: 'Bearer abc123' });

This would allow us in Cloud functions to simply pass the auth header of the request along to the new request.

Alternatives / Workarounds

  • Use CoreManager -> Not a good idea
  • Revert to use artificial sessions for users to be able to pass a session token -> Requires a lot of additional code to manage these sessions, protect them correctly etc., as they are a potential security hole if leaked - which works against the purpose of using OAuth2 / JWT approach
  • Not use the JS SDK in cloud functions and call the REST API instead with axios or sth. else -> less comfortable solution and some features have to be implemented manually, e.g. batch requests...

3rd Party References

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions