-
Notifications
You must be signed in to change notification settings - Fork 192
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
chore: Refactor Auth Token Middleware's token logic #492
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way you have it now seems to be making more changes than necessary. If the goal of this PR is to just to use updateMetadata
when available, I think it would be better to simplify this logic as something like this:
// Use "updateMetadata" if it exists, otherwise use "fetchAuthToken"
if (!$this->fetcher instanceof UpdateMetadataInterface ||
($this->fetcher FetchAuthTokenCache && !$this->fetcher->getFetcher() instanceof UpdateMetadataInterface)
) {
// previous behavior (unlikely - only happens if user supplies a custom fetcher)
$request = $request->withHeader('authorization', 'Bearer ' . $this->fetchToken());
} else {
// new behavior - allow the credentials to add / update request headers
$updatedHeaders = $this->fetcher->updateMetadata($request->getHeaders(), null, $this->httpHandler);
$request = Utils::modifyRequest($request, ['set_headers' => $updatedHeaders]);
}
Thanks for the pointer. We would be required to fetch auth token when using update metadata because we need to call the token callback in the event it isn't an identity token request. I've amended the logic as such, please take a look. Now it looks cleaner. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff! We're getting closer here.
Co-authored-by: Brent Shaffer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! I only have some suggestions on how to improve the tests.
Delegate Auth Metadata logic to Auth Library
Implement the go/php-auth-token-unifomity design to delegate token fetching and metadata updation logic to the auth library, resulting transfer of auth metadata control to auth library, thus unifying the token flow.
Post this change, all the php api client services libraries would adhere to go/php-auth-token-unifomity.