-
Notifications
You must be signed in to change notification settings - Fork 170
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
SNOW-1825482: PAT + OAuth Authorization Code + OAuth Client Credentials support #1978
base: master
Are you sure you want to change the base?
Conversation
119a205
to
195ff36
Compare
ec6effb
to
a3dad01
Compare
…bc into oauth-code-flow
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
@@ -218,6 +219,11 @@ | |||
<artifactId>nimbus-jose-jwt</artifactId> | |||
<version>${nimbusds.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.nimbusds</groupId> | |||
<artifactId>oauth2-oidc-sdk</artifactId> |
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.
do we have security review finished for this library?
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.
Not yet
TokenRequest request = buildTokenRequest(loginInput, authorizationCode, pkceVerifier); | ||
URI requestUri = request.getEndpointURI(); | ||
logger.debug( | ||
"Requesting access token from: " + requestUri.getAuthority() + requestUri.getPath()); |
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.
please use logger parameters instead of string concatenation, also in other logs
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.
Done.
...main/java/net/snowflake/client/core/auth/oauth/AuthorizationCodeFlowAccessTokenProvider.java
Outdated
Show resolved
Hide resolved
...main/java/net/snowflake/client/core/auth/oauth/AuthorizationCodeFlowAccessTokenProvider.java
Outdated
Show resolved
Hide resolved
...main/java/net/snowflake/client/core/auth/oauth/AuthorizationCodeFlowAccessTokenProvider.java
Outdated
Show resolved
Hide resolved
src/main/java/net/snowflake/client/core/auth/oauth/TokenResponseDTO.java
Show resolved
Hide resolved
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.
Looks good to me in general, I will need a second look once I get some more knowledge about OAuth
@@ -29,6 +29,12 @@ public enum SFSessionProperty { | |||
AUTHENTICATOR("authenticator", false, String.class), | |||
OKTA_USERNAME("oktausername", false, String.class), | |||
PRIVATE_KEY("privateKey", false, PrivateKey.class), | |||
OAUTH_REDIRECT_URI("redirectUri", false, String.class), | |||
CLIENT_ID("clientID", false, String.class), |
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.
oauthClientId, oauthClientSecret etc.?
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'd prefer not to introduce new parameters, after all user can use only one authentication type at a time
}, | ||
"bodyPatterns": [ | ||
{ | ||
"contains": "grant_type=authorization_code&code=123&redirect_uri=http%3A%2F%2Flocalhost%3A8001%2Fsnowflake%2Foauth-redirect&code_verifier=" |
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.
Please verify if we indeed use PKCE
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.
yes, we need to.
} | ||
|
||
@Test | ||
public void browserTimeoutFlowScenario() { |
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.
These error tests seem very similar, maybe we could make them parameterized? For keeping descriptive names, see Arguments.argumentSet
(in case of @ArgumentProvider
).
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'd do it after client credentials flow is added, because I'm not yet sure if these will remain as they are.
/* | ||
* Authorization code flow with browser popup | ||
*/ | ||
OAUTH_AUTHORIZATION_CODE |
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.
maybe CLIENT_OAUTH would be a good name from this OAuth flows to make it different than OAuth and indicate it's on client side, WDYT? @sfc-gh-dprzybysz @sfc-gh-dheyman @sfc-gh-pfus
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 like it. CLIENT_OAUTH is too generic. Dawid's name seems better to me.
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 would rather change the original OAUTH authenticator to OAUTH_ACCESS_TOKEN or something like that, but I understand it would be a BCR.
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.
@sfc-gh-eworoshow WDYT? did you go through any naming discussion already
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 see a couple options:
AUTHENTICATOR=OAUTH
plusOAUTH_FLOW={TOKEN | AUTHORIZATION_CODE | CLIENT_CREDENTIALS }
, whereTOKEN
is our existing default.AUTHENTICATOR={OAUTH | OAUTH_ACCESS_TOKEN, alias of OAUTH | OAUTH_AUTHORIZATION_CODE | ... }
.
In both cases I think we should use the "standard" name for the OAuth flow we're implementing.
linkage-checker-exclusion-rules.xml
Outdated
@@ -14,11 +14,6 @@ | |||
<Source><Package name="com.nimbusds.jose"/></Source> | |||
<Reason>Optional</Reason> | |||
</LinkageError> | |||
<LinkageError> | |||
<Target><Package name="org.brotli.dec"/></Target> |
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.
Why do we want to delete these lines?
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.
Restored.
/* | ||
* Authorization code flow with browser popup | ||
*/ | ||
OAUTH_AUTHORIZATION_CODE |
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 like it. CLIENT_OAUTH is too generic. Dawid's name seems better to me.
String code = codeFuture.get(this.browserAuthorizationTimeoutSeconds, TimeUnit.SECONDS); | ||
return new AuthorizationCode(code); | ||
} catch (Exception e) { | ||
if (e instanceof TimeoutException) { |
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.
Why not catch (TimeoutException)
?
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 idea, fixed.
private final long expiresIn; | ||
private final long refreshTokenExpiresIn; | ||
|
||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES) |
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.
What if some of these properties are missing? Will nulls
be used?
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.
Yes
@@ -0,0 +1,51 @@ | |||
package net.snowflake.client.core; |
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.
let's add license header like in other files
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.
Added
try { | ||
TokenRequest request = buildTokenRequest(loginInput, authorizationCode, pkceVerifier); | ||
URI requestUri = request.getEndpointURI(); | ||
logger.debug( | ||
"Requesting access token from: " + requestUri.getAuthority() + requestUri.getPath()); | ||
"Requesting access token from: {}", requestUri.getAuthority() + requestUri.getPath()); |
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 concatenate in formatted string:
"Requesting access token from: {}{}", requestUri.getAuthority(), requestUri.getPath()
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.
Done
|
||
@SnowflakeJdbcInternalApi |
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.
package scope class does not need internal annotation
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.
Removed
Overview
SNOW-1825482: PAT + OAuth Authorization Code + OAuth Client Credentials support
Pre-review self checklist
master
branchmvn -P check-style validate
)mvn verify
and inspecttarget/japicmp/japicmp.html
)SNOW-XXXX:
External contributors - please answer these questions before submitting a pull request. Thanks!
What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Issue: #NNNN
Fill out the following pre-review checklist:
@SnowflakeJdbcInternalApi
(note that public/protected methods/fields in classes marked with this annotation are already internal)Please describe how your code solves the related issue.
Please write a short description of how your code change solves the related issue.