-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add keycloak OAuth provider #13033
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
Open
tazouxme
wants to merge
13
commits into
apache:main
Choose a base branch
from
tazouxme:feature/add_keycloak_oauth_provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+655
−86
Open
Add keycloak OAuth provider #13033
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
66d0344
Add Keycloak OAuth Provider: first commit
c7c7297
Fix issue
506f664
Cache idToken
28ea821
Fix variables
3d037ab
Add labels
a0270e1
Change error message
63cc3bf
Add Licence
beb64d4
Fix bad change
cc18f82
Fix findings from Copilot review
1a543ae
pre-commit fix
9df0c38
Merge branch 'main' into feature/add_keycloak_oauth_provider
DaanHoogland 400bd09
Review from Copilot
95bd89d
Fix formatting issue
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
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 |
|---|---|---|
|
|
@@ -14,26 +14,28 @@ | |
| // limitations under the License. | ||
| package org.apache.cloudstack.oauth2.api.command; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Map; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.persistence.EntityExistsException; | ||
|
|
||
| import org.apache.cloudstack.api.response.SuccessResponse; | ||
| import org.apache.cloudstack.oauth2.OAuth2AuthManager; | ||
| import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse; | ||
| import org.apache.cloudstack.oauth2.vo.OauthProviderVO; | ||
| import org.apache.commons.collections.MapUtils; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.SuccessResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.oauth2.OAuth2AuthManager; | ||
| import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse; | ||
| import org.apache.cloudstack.oauth2.vo.OauthProviderVO; | ||
| import org.apache.commons.collections.MapUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import com.cloud.exception.ConcurrentOperationException; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Map; | ||
|
|
||
| @APICommand(name = "registerOauthProvider", responseObject = SuccessResponse.class, description = "Register the OAuth2 provider in CloudStack", since = "4.19.0") | ||
| public class RegisterOAuthProviderCmd extends BaseCmd { | ||
|
|
||
|
|
@@ -56,6 +58,12 @@ public class RegisterOAuthProviderCmd extends BaseCmd { | |
| @Parameter(name = ApiConstants.REDIRECT_URI, type = CommandType.STRING, description = "Redirect URI pre-registered in the specific OAuth provider", required = true) | ||
| private String redirectUri; | ||
|
|
||
| @Parameter(name = ApiConstants.AUTHORIZE_URL, type = CommandType.STRING, description = "Authorize URL for OAuth initialization (only required for keycloack provider)") | ||
| private String authorizeUrl; | ||
|
|
||
| @Parameter(name = ApiConstants.TOKEN_URL, type = CommandType.STRING, description = "Token URL for OAuth finalization (only required for keycloak provider)") | ||
| private String tokenUrl; | ||
|
|
||
| @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, | ||
| description = "Any OAuth provider details in key/value pairs using format details[i].keyname=keyvalue. Example: details[0].clientsecret=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") | ||
| protected Map details; | ||
|
|
@@ -85,6 +93,14 @@ public String getRedirectUri() { | |
| return redirectUri; | ||
| } | ||
|
|
||
| public String getAuthorizeUrl() { | ||
| return authorizeUrl; | ||
| } | ||
|
|
||
| public String getTokenUrl() { | ||
| return tokenUrl; | ||
| } | ||
|
|
||
| public Map getDetails() { | ||
| if (MapUtils.isEmpty(details)) { | ||
| return null; | ||
|
|
@@ -98,10 +114,20 @@ public Map getDetails() { | |
|
|
||
| @Override | ||
| public void execute() throws ServerApiException, ConcurrentOperationException, EntityExistsException { | ||
| if (StringUtils.equals("keycloak", getProvider())) { | ||
|
Member
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. is it possible to use some constants here ? |
||
| if (StringUtils.isBlank(getAuthorizeUrl())) { | ||
| throw new ServerApiException(ApiErrorCode.BAD_REQUEST, "Parameter authorizeurl is mandatory for keycloak OAuth Provider"); | ||
| } | ||
| if (StringUtils.isBlank(getTokenUrl())) { | ||
| throw new ServerApiException(ApiErrorCode.BAD_REQUEST, "Parameter tokenurl is mandatory for keycloak OAuth Provider"); | ||
| } | ||
| } | ||
|
|
||
| OauthProviderVO provider = _oauth2mgr.registerOauthProvider(this); | ||
|
|
||
| OauthProviderResponse response = new OauthProviderResponse(provider.getUuid(), provider.getProvider(), | ||
| provider.getDescription(), provider.getClientId(), provider.getSecretKey(), provider.getRedirectUri()); | ||
| provider.getDescription(), provider.getClientId(), provider.getSecretKey(), provider.getRedirectUri(), | ||
| provider.getAuthorizeUrl(), provider.getTokenUrl()); | ||
| response.setResponseName(getCommandName()); | ||
| response.setObjectName(ApiConstants.OAUTH_PROVIDER); | ||
| setResponseObject(response); | ||
|
|
||
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
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.
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.
If these are only required for keycloak provider, can we use the existing details map, instead of these parameters ?
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.
if you think these can be used later for other providers, keep the description accordingly.