-
Notifications
You must be signed in to change notification settings - Fork 227
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
feat: adding support for authentication type on UserAuthorizer #1421
Conversation
@@ -206,7 +210,8 @@ public LowLevelHttpResponse execute() throws IOException { | |||
} | |||
String foundSecret = query.get("client_secret"); | |||
String expectedSecret = clients.get(foundId); | |||
if (foundSecret == null || !foundSecret.equals(expectedSecret)) { | |||
if ((foundSecret == null || !foundSecret.equals(expectedSecret)) | |||
&& clients.get("Authorization") == null) { |
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.
I don't think we are validating the auth header anywhere.
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 the limitation of MockTokenServerTransport
as it doesn't capture request header during it's execute
method. So we have to use an addHeader
method to simulate what has been added to the headers. And then in the test code call we cal this addHeader
prior to make the http request.
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.
You can get the request header -- we do it in other tests I'm pretty sure
Co-authored-by: Leo <39062083+lsirac@users.noreply.github.com>
Co-authored-by: Leo <39062083+lsirac@users.noreply.github.com>
The library methods here return UserCredentials. Is this compatible with BYOID? We have ExternalAccountAuthorizedUserCredentials for BYOID. |
|
oauth2_http/javatests/com/google/auth/oauth2/MockTokenServerTransport.java
Outdated
Show resolved
Hide resolved
oauth2_http/javatests/com/google/auth/oauth2/MockTokenServerTransport.java
Outdated
Show resolved
Hide resolved
Quality Gate passedIssues Measures |
The method you've updated here returns UserCredentials. This is not compatible with the BYOID flow. |
Maybe this is not the same flow with our existing BYOID flow. I believe the flow is still work as help the |
PKCEProvider pkce, | ||
ClientAuthenticationType clientAuthentication) { |
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.
Since this is a private constructor, can we update this to take in the Builder class instead of additional parameters?
private UserAuthorizer(Builder builder) {
// Assign the fields.
}
If we change this constructor to take a Builder, then the javadocs suggestion above doesn't matter.
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.
I don't think so. The Builder
's build()
method is using this parameter to initialize the value.
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.
I believe you can change the builder's build() method so that it pass the builder as the sole parameter to the constructor:
public UserAuthorizer build() {
return new UserAuthorizer(this);
}
I think this would be cleaner because future implementations can add additional params without having to explicitly new fields to the constructor:
private UserAuthorizer(UserAuthorizer.Builder builder) {
this.clientId = Preconditions.checkNotNull(builder.clientId);
this.scopes = ImmutableList.copyOf(Preconditions.checkNotNull(builder.scopes));
this.callbackUri = (builder.callbackUri == null) ? DEFAULT_CALLBACK_URI : builder.callbackUri;
this.transportFactory =
(builder.transportFactory == null) ? OAuth2Utils.HTTP_TRANSPORT_FACTORY : builder.transportFactory;
this.tokenServerUri = (builder.tokenServerUri == null) ? OAuth2Utils.TOKEN_SERVER_URI : builder.tokenServerUri;
this.userAuthUri = (builder.userAuthUri == null) ? OAuth2Utils.USER_AUTH_URI : builder.userAuthUri;
this.tokenStore = (builder.tokenStore == null) ? new MemoryTokensStorage() : builder.tokenStore;
this.pkce = builder.pkce;
this.clientAuthenticationType =
(builder.clientAuthenticationType == null)
? ClientAuthenticationType.CLIENT_SECRET_POST
: builder.clientAuthenticationType;
}
I think this can be refactored even more, so that the builder sets default values and it doesn't need to be validated in the constructor:
public static class Builder {
private ClientId clientId;
private TokenStore tokenStore = new MemoryTokensStorage();
private URI callbackUri = DEFAULT_CALLBACK_URI;
private URI tokenServerUri = OAuth2Utils.TOKEN_SERVER_URI;
private URI userAuthUri = OAuth2Utils.USER_AUTH_URI;
private Collection<String> scopes;
private HttpTransportFactory transportFactory = OAuth2Utils.HTTP_TRANSPORT_FACTORY;
private PKCEProvider pkce;
private ClientAuthenticationType clientAuthenticationType = ClientAuthenticationType.CLIENT_SECRET_POST;
...
and the constructor could be something like:
private UserAuthorizer(UserAuthorizer.Builder builder) {
this.clientId = Preconditions.checkNotNull(builder.clientId);
this.scopes = ImmutableList.copyOf(Preconditions.checkNotNull(builder.scopes));
this.callbackUri = builder.callbackUri;
this.transportFactory = builder.transportFactory;
this.tokenServerUri = builder.tokenServerUri;
this.userAuthUri = builder.userAuthUri;
this.tokenStore = builder.tokenStore;
this.pkce = builder.pkce;
this.clientAuthenticationType = builder.clientAuthenticationType;
}
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 refactor make sense to me. But that's sort of a bigger refactor than this change and irrelevant to the purpose of this change.
Can I do a separate one for that? Maybe create an issue and resolve it through the refactor change.
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.
Sure, it's a private constructor and we can change implementation later. If you could create an issue in this repo and follow up on it sometime in the coming weeks, that would be great! Thanks!
Quality Gate passedIssues Measures |
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> ☕️
The change basically following the logic that NodeJS change: googleapis/google-auth-library-nodejs#1814
The key point is telling the client how are the
UserAuthorizer
going to provide auth with token URI.Our current way is to have
client_secret
sending as part of the post url parameter. The STS endpoint won't allow that and they are not acceptingclient_secret
field. Instead, the STS is using basic auth which takes a base64 encoding ofclient_id:client_secret
.Here the change is to provide a parameter to
UserAuthorizer
which auth from #RFC we are using and set thePOST
(Current way) as default.Then in the implementation, when sending the token request, we apply a basic auth header if the authentication type is set to
BASIC
.If you write sample code, please follow the samples format.