-
Notifications
You must be signed in to change notification settings - Fork 57
Complete OAuth2 authorization support #1446
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d0327cb
Complete OAuth2 authorization support
mcruzdev e21f4c0
Provide revoke and introspection methods to AccessTokenProvider
mcruzdev 05d269a
ormat code
mcruzdev 52ad329
Self-review
mcruzdev aa642d0
Self-review
mcruzdev deac24e
Apply pull request suggestions
mcruzdev 89fa073
Rollback .gitignore
mcruzdev d758ecf
Remove introspection and revoke
mcruzdev 73e56da
Address comments
mcruzdev b8fbe08
Remove ununsed class
mcruzdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
impl/core/src/main/java/io/serverlessworkflow/impl/auth/JwtClientAssertion.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.auth; | ||
|
|
||
| import static io.serverlessworkflow.api.types.OAuth2AuthenticationData.OAuth2AuthenticationDataGrant.PASSWORD; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.ASSERTION; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.CLIENT; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.CLIENT_ASSERTION; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.CLIENT_ASSERTION_TYPE; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.CLIENT_ID; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.GRANT; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.ID; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.JWT_BEARER_ASSERTION_TYPE; | ||
| import static io.serverlessworkflow.impl.auth.AuthUtils.USER; | ||
|
|
||
| import io.serverlessworkflow.api.types.OAuth2AuthenticationData; | ||
| import io.serverlessworkflow.impl.WorkflowApplication; | ||
| import io.serverlessworkflow.impl.WorkflowUtils; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Handles the {@code client_secret_jwt} and {@code private_key_jwt} client authentication methods. | ||
| * | ||
| * <p>Per the Serverless Workflow specification, the caller supplies a pre-signed JWT through {@code | ||
| * client.assertion}. Both methods are forwarded identically: the assertion is sent as {@code | ||
| * client_assertion} together with the standard {@code client_assertion_type} defined by RFC 7523. | ||
| * The signing algorithm (HMAC for {@code client_secret_jwt}, an asymmetric key for {@code | ||
| * private_key_jwt}) is the caller's responsibility. | ||
| */ | ||
| class JwtClientAssertion extends ClientSecretHandler { | ||
|
|
||
| protected JwtClientAssertion( | ||
| WorkflowApplication application, HttpRequestInfoBuilder requestBuilder) { | ||
| super(application, requestBuilder); | ||
| } | ||
|
|
||
| @Override | ||
| void accept(OAuth2AuthenticationData authenticationData) { | ||
| if (authenticationData.getClient() == null | ||
| || authenticationData.getClient().getAssertion() == null) { | ||
| throw new IllegalArgumentException( | ||
| "A client assertion must be provided for JWT client authentication"); | ||
| } | ||
| if (authenticationData.getGrant().equals(PASSWORD)) { | ||
| if (authenticationData.getUsername() == null || authenticationData.getPassword() == null) { | ||
| throw new IllegalArgumentException( | ||
| "Username and password must be provided for password grant type"); | ||
| } | ||
| password(authenticationData); | ||
| } else { | ||
| clientCredentials(authenticationData); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| void accept(Map<String, Object> secret) { | ||
| Map<String, Object> client = asClient(secret); | ||
| if (client == null || client.get(ASSERTION) == null) { | ||
| throw new IllegalArgumentException( | ||
| "A client assertion must be provided for JWT client authentication"); | ||
| } | ||
| if (PASSWORD.value().equals(secret.get(GRANT))) { | ||
| password(secret); | ||
| } else { | ||
| clientCredentials(secret); | ||
| } | ||
| } | ||
|
Comment on lines
+69
to
+84
Collaborator
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. @mcruzdev I think that one is valid too |
||
|
|
||
| @Override | ||
| protected void clientCredentials(OAuth2AuthenticationData authenticationData) { | ||
| requestBuilder.withGrantType(authenticationData.getGrant().value()); | ||
| addAssertion( | ||
| authenticationData.getClient().getId(), authenticationData.getClient().getAssertion()); | ||
| } | ||
|
|
||
| @Override | ||
| protected void password(OAuth2AuthenticationData authenticationData) { | ||
| clientCredentials(authenticationData); | ||
| requestBuilder | ||
| .addQueryParam( | ||
| "username", | ||
| WorkflowUtils.buildStringFilter(application, authenticationData.getUsername())) | ||
| .addQueryParam( | ||
| "password", | ||
| WorkflowUtils.buildStringFilter(application, authenticationData.getPassword())); | ||
| } | ||
|
|
||
| @Override | ||
| protected void clientCredentials(Map<String, Object> secret) { | ||
| Map<String, Object> client = asClient(secret); | ||
| requestBuilder.withGrantType((String) secret.get(GRANT)); | ||
| addAssertion((String) client.get(ID), (String) client.get(ASSERTION)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void password(Map<String, Object> secret) { | ||
| clientCredentials(secret); | ||
| requestBuilder | ||
| .addQueryParam("username", (String) secret.get(USER)) | ||
| .addQueryParam("password", (String) secret.get(AuthUtils.PASSWORD)); | ||
| } | ||
|
|
||
| private void addAssertion(String clientId, String assertion) { | ||
| if (clientId != null) { | ||
| requestBuilder.addQueryParam( | ||
| CLIENT_ID, WorkflowUtils.buildStringFilter(application, clientId)); | ||
| } | ||
| requestBuilder | ||
| .addQueryParam(CLIENT_ASSERTION_TYPE, JWT_BEARER_ASSERTION_TYPE) | ||
| .addQueryParam(CLIENT_ASSERTION, WorkflowUtils.buildStringFilter(application, assertion)); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static Map<String, Object> asClient(Map<String, Object> secret) { | ||
| return (Map<String, Object>) secret.get(CLIENT); | ||
| } | ||
|
fjtirado marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.