Skip to content
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

Fix factory method for AmazonCognitoAuth #711

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.ext.auth.JWTOptions;
import io.vertx.ext.auth.oauth2.OAuth2Auth;
import io.vertx.ext.auth.oauth2.OAuth2Options;

Expand All @@ -37,10 +38,11 @@ public interface AmazonCognitoAuth extends OpenIDConnectAuth {
* @param region the region to use
* @param clientId the client id given to you by Amazon Cognito
* @param clientSecret the client secret given to you by Amazon Cognito
* @param domain the Cognito domain
* @param guid the guid of your application given to you by Amazon Cognito
*/
static OAuth2Auth create(Vertx vertx, String region, String clientId, String clientSecret, String guid) {
return create(vertx, region, clientId, clientSecret, guid, new HttpClientOptions());
static OAuth2Auth create(Vertx vertx, String region, String clientId, String clientSecret, String domain, String guid) {
return create(vertx, region, clientId, clientSecret, domain, guid, new HttpClientOptions());
}

/**
Expand All @@ -49,27 +51,33 @@ static OAuth2Auth create(Vertx vertx, String region, String clientId, String cli
* @param region the region to use
* @param clientId the client id given to you by Amazon Cognito
* @param clientSecret the client secret given to you by Amazon Cognito
* @param domain the Cognito domain
* @param userPoolId the userPoolId of your application given to you by Amazon Cognito
* @param httpClientOptions custom http client options
*/
static OAuth2Auth create(Vertx vertx, String region, String clientId, String clientSecret, String userPoolId, HttpClientOptions httpClientOptions) {
static OAuth2Auth create(Vertx vertx, String region, String clientId, String clientSecret, String domain, String userPoolId, HttpClientOptions httpClientOptions) {
if (region == null) {
throw new IllegalStateException("region cannot be null");
}

final String siteBase = String.format("https://cognito-idp.%s.amazonaws.com", region);
final String domainUrl = String.format("https://%s.auth.%s.amazoncognito.com", domain, region);

return
OAuth2Auth.create(vertx, new OAuth2Options()
.setHttpClientOptions(httpClientOptions)
.setClientId(clientId)
.setClientSecret(clientSecret)
.setTenant(userPoolId)
.setSite("https://cognito-idp." + region + ".amazonaws.com/{tenant}")
.setTokenPath("/oauth2/token")
.setAuthorizationPath("/oauth2/authorize")
.setUserInfoPath("/oauth2/userInfo")
.setJwkPath("/.well-known/jwks.json")
.setLogoutPath("/logout")
.setScopeSeparator("+"));
.setSite(siteBase + "/{tenant}")
.setTokenPath(domainUrl + "/oauth2/token")
.setAuthorizationPath(domainUrl + "/oauth2/authorize")
.setUserInfoPath(domainUrl + "/oauth2/userInfo")
.setRevocationPath(domainUrl + "/oauth/revoke")
.setJwkPath(siteBase + "/{tenant}/.well-known/jwks.json")
.setLogoutPath(domainUrl + "/logout")
.setScopeSeparator(" ")
.setJWTOptions(new JWTOptions().setIssuer(siteBase + "/{tenant}")));
}

/**
Expand Down
Loading