-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Support usage of Separate Authorization Server URI in Rest Catalog #8976
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
Changes from all commits
602fad8
0786dc4
17a42bd
18bedd5
c9f0c30
5f53997
a106e39
1541c9f
47047cb
30d8075
3620884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,8 @@ private static OAuthTokenResponse refreshToken( | |
| Map<String, String> headers, | ||
| String subjectToken, | ||
| String subjectTokenType, | ||
| String scope) { | ||
| String scope, | ||
| String oauth2ServerUri) { | ||
danielcweeks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Map<String, String> request = | ||
| tokenExchangeRequest( | ||
| subjectToken, | ||
|
|
@@ -143,7 +144,7 @@ private static OAuthTokenResponse refreshToken( | |
|
|
||
| OAuthTokenResponse response = | ||
| client.postForm( | ||
| ResourcePaths.tokens(), | ||
| oauth2ServerUri, | ||
| request, | ||
| OAuthTokenResponse.class, | ||
| headers, | ||
|
|
@@ -160,7 +161,8 @@ public static OAuthTokenResponse exchangeToken( | |
| String subjectTokenType, | ||
| String actorToken, | ||
| String actorTokenType, | ||
| String scope) { | ||
| String scope, | ||
| String oauth2ServerUri) { | ||
| Map<String, String> request = | ||
| tokenExchangeRequest( | ||
| subjectToken, | ||
|
|
@@ -171,7 +173,7 @@ public static OAuthTokenResponse exchangeToken( | |
|
|
||
| OAuthTokenResponse response = | ||
| client.postForm( | ||
| ResourcePaths.tokens(), | ||
| oauth2ServerUri, | ||
| request, | ||
| OAuthTokenResponse.class, | ||
| headers, | ||
|
|
@@ -181,15 +183,38 @@ public static OAuthTokenResponse exchangeToken( | |
| return response; | ||
| } | ||
|
|
||
| public static OAuthTokenResponse exchangeToken( | ||
| RESTClient client, | ||
| Map<String, String> headers, | ||
| String subjectToken, | ||
| String subjectTokenType, | ||
| String actorToken, | ||
| String actorTokenType, | ||
| String scope) { | ||
| return exchangeToken( | ||
| client, | ||
| headers, | ||
| subjectToken, | ||
| subjectTokenType, | ||
| actorToken, | ||
| actorTokenType, | ||
| scope, | ||
| ResourcePaths.tokens()); | ||
| } | ||
|
|
||
| public static OAuthTokenResponse fetchToken( | ||
| RESTClient client, Map<String, String> headers, String credential, String scope) { | ||
| RESTClient client, | ||
| Map<String, String> headers, | ||
| String credential, | ||
| String scope, | ||
| String oauth2ServerUri) { | ||
| Map<String, String> request = | ||
| clientCredentialsRequest( | ||
| credential, scope != null ? ImmutableList.of(scope) : ImmutableList.of()); | ||
|
|
||
| OAuthTokenResponse response = | ||
| client.postForm( | ||
| ResourcePaths.tokens(), | ||
| oauth2ServerUri, | ||
| request, | ||
| OAuthTokenResponse.class, | ||
| headers, | ||
|
|
@@ -199,6 +224,12 @@ public static OAuthTokenResponse fetchToken( | |
| return response; | ||
| } | ||
|
|
||
| public static OAuthTokenResponse fetchToken( | ||
| RESTClient client, Map<String, String> headers, String credential, String scope) { | ||
|
|
||
| return fetchToken(client, headers, credential, scope, ResourcePaths.tokens()); | ||
| } | ||
|
|
||
| private static Map<String, String> tokenExchangeRequest( | ||
| String subjectToken, String subjectTokenType, List<String> scopes) { | ||
| return tokenExchangeRequest(subjectToken, subjectTokenType, null, null, scopes); | ||
|
|
@@ -361,7 +392,26 @@ public static class AuthSession { | |
| private final String credential; | ||
| private final String scope; | ||
| private volatile boolean keepRefreshed = true; | ||
| private final String oauth2ServerUri; | ||
|
|
||
| public AuthSession( | ||
danielcweeks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Map<String, String> baseHeaders, | ||
| String token, | ||
| String tokenType, | ||
| String credential, | ||
| String scope, | ||
| String oauth2ServerUri) { | ||
| this.headers = RESTUtil.merge(baseHeaders, authHeaders(token)); | ||
| this.token = token; | ||
| this.tokenType = tokenType; | ||
| this.expiresAtMillis = OAuth2Util.expiresAtMillis(token); | ||
| this.credential = credential; | ||
| this.scope = scope; | ||
| this.oauth2ServerUri = oauth2ServerUri; | ||
| } | ||
|
|
||
| /** @deprecated since 1.5.0, will be removed in 1.6.0 */ | ||
| @Deprecated | ||
| public AuthSession( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it is not used anywhere. Should we deprecate it? If that's so, can we add deprecation comment?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that too. I lack the context to make that decision, so I will leave this comment thread for others to opine
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't appear to be referenced anymore so you should add a deprecation warning and message (see deprecation docs) |
||
| Map<String, String> baseHeaders, | ||
| String token, | ||
|
|
@@ -374,6 +424,7 @@ public AuthSession( | |
| this.expiresAtMillis = OAuth2Util.expiresAtMillis(token); | ||
| this.credential = credential; | ||
| this.scope = scope; | ||
| this.oauth2ServerUri = ResourcePaths.tokens(); | ||
| } | ||
|
|
||
| public Map<String, String> headers() { | ||
|
|
@@ -404,6 +455,10 @@ public String credential() { | |
| return credential; | ||
| } | ||
|
|
||
| public String oauth2ServerUri() { | ||
| return oauth2ServerUri; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static void setTokenRefreshNumRetries(int retries) { | ||
| tokenRefreshNumRetries = retries; | ||
|
|
@@ -415,7 +470,8 @@ static void setTokenRefreshNumRetries(int retries) { | |
| * @return A new {@link AuthSession} with empty headers. | ||
| */ | ||
| public static AuthSession empty() { | ||
| return new AuthSession(ImmutableMap.of(), null, null, null, OAuth2Properties.CATALOG_SCOPE); | ||
| return new AuthSession( | ||
| ImmutableMap.of(), null, null, null, OAuth2Properties.CATALOG_SCOPE, null); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -470,14 +526,14 @@ private OAuthTokenResponse refreshCurrentToken(RESTClient client) { | |
| return refreshExpiredToken(client); | ||
| } else { | ||
| // attempt a normal refresh | ||
| return refreshToken(client, headers(), token, tokenType, scope); | ||
| return refreshToken(client, headers(), token, tokenType, scope, oauth2ServerUri); | ||
| } | ||
| } | ||
|
|
||
| private OAuthTokenResponse refreshExpiredToken(RESTClient client) { | ||
| if (credential != null) { | ||
| Map<String, String> basicHeaders = RESTUtil.merge(headers(), basicAuthHeaders(credential)); | ||
| return refreshToken(client, basicHeaders, token, tokenType, scope); | ||
| return refreshToken(client, basicHeaders, token, tokenType, scope, oauth2ServerUri); | ||
| } | ||
|
|
||
| return null; | ||
|
|
@@ -533,7 +589,8 @@ public static AuthSession fromAccessToken( | |
| token, | ||
| OAuth2Properties.ACCESS_TOKEN_TYPE, | ||
| parent.credential(), | ||
| parent.scope()); | ||
| parent.scope(), | ||
| parent.oauth2ServerUri()); | ||
|
|
||
| long startTimeMillis = System.currentTimeMillis(); | ||
| Long expiresAtMillis = session.expiresAtMillis(); | ||
|
|
@@ -571,7 +628,8 @@ public static AuthSession fromCredential( | |
| AuthSession parent) { | ||
| long startTimeMillis = System.currentTimeMillis(); | ||
| OAuthTokenResponse response = | ||
| fetchToken(client, parent.headers(), credential, parent.scope()); | ||
| fetchToken( | ||
| client, parent.headers(), credential, parent.scope(), parent.oauth2ServerUri()); | ||
| return fromTokenResponse(client, executor, response, startTimeMillis, parent, credential); | ||
| } | ||
|
|
||
|
|
@@ -598,7 +656,8 @@ private static AuthSession fromTokenResponse( | |
| response.token(), | ||
| response.issuedTokenType(), | ||
| credential, | ||
| parent.scope()); | ||
| parent.scope(), | ||
| parent.oauth2ServerUri()); | ||
|
|
||
| Long expiresAtMillis = session.expiresAtMillis(); | ||
| if (null == expiresAtMillis && response.expiresInSeconds() != null) { | ||
|
|
@@ -627,7 +686,8 @@ public static AuthSession fromTokenExchange( | |
| tokenType, | ||
| parent.token(), | ||
| parent.tokenType(), | ||
| parent.scope()); | ||
| parent.scope(), | ||
| parent.oauth2ServerUri()); | ||
| return fromTokenResponse(client, executor, response, startTimeMillis, parent); | ||
| } | ||
| } | ||
|
|
||
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.
"Token endpoint URI" -> "OAuth Server URI" or just "Endpoint"?