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

[SDK-3268] Add bearer token extraction helper #620

Merged
merged 5 commits into from
Apr 21, 2022

Conversation

evansims
Copy link
Member

@evansims evansims commented Apr 19, 2022

This PR adds a new method to the SDK class, getBearerToken(). This method is highly configurable and enable a developer to pull an available bearer token from a request from a variety of sources (request parameters, post body, etc.) while avoiding writing considerable and redundant boilerplate code.

Example usage:

$sdk->getBearerToken(
  get: ['token'],
  server: ['Authorization']
);

This would fetch and process an available access token from either an incoming GET request via a parameter named 'token', or from the request's “Authorization” header, where it might find a bearer token. The method silently ignores invalid or missing tokens from any provided candidate.

The PR adds several new tests to add coverage for the new method. Code coverage remains at 100%.

@evansims evansims requested a review from a team as a code owner April 19, 2022 00:31
@evansims evansims changed the title Add bearer token extraction helper [SDL-3268] Add bearer token extraction helper Apr 19, 2022
@evansims evansims changed the title [SDL-3268] Add bearer token extraction helper [SDK-3268] Add bearer token extraction helper Apr 19, 2022
$cache->save($item);

$response->cached = $cache;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a convenience addition for our test suite; now returns a pre-configured JWKS cache suitable for testing a given key, rather than having to redundantly do this within each test individually. Adds a little overhead to each test run that generates a token, but not significant enough to outweigh the convenience.

@evansims evansims merged commit 4bca039 into main Apr 21, 2022
@evansims evansims deleted the feat/add-bearer-token-extractor branch April 21, 2022 04:08
@ca-dsgn
Copy link

ca-dsgn commented Apr 22, 2022

@evansims I am just looking for a native way to get the Bearer token and found your update. Great that this is already implemented. When will this update be available via composer? Is it part of the next Release 8.2.0?

@evansims evansims mentioned this pull request Apr 25, 2022
@evansims
Copy link
Member Author

@ca-dsgn Apologies, somehow overlooked your reply! 8.2 has just been released today, which includes this method. 👍 Please do let me know any feedback you might have on how it works

@ca-dsgn
Copy link

ca-dsgn commented May 17, 2022

@evansims Is there already an example on how to use the getBearerToken() function? I tried several ways, but I am always getting null back from the function.

@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants