use of org.mule.runtime.extension.api.connectivity.oauth.AuthorizationCodeGrantType in project mule by mulesoft.
the class DefaultExtensionsOAuthManager method createDancer.
private AuthorizationCodeOAuthDancer createDancer(OAuthConfig config) throws MuleException {
OAuthAuthorizationCodeDancerBuilder dancerBuilder = oauthService.get().authorizationCodeGrantTypeDancerBuilder(lockId -> lockFactory.createLock(lockId), new LazyObjectStoreToMapAdapter(getObjectStoreSupplier(config)), expressionEvaluator);
final AuthCodeConfig authCodeConfig = config.getAuthCodeConfig();
final AuthorizationCodeGrantType grantType = config.getGrantType();
final OAuthCallbackConfig callbackConfig = config.getCallbackConfig();
dancerBuilder.encoding(getDefaultEncoding(muleContext)).clientCredentials(authCodeConfig.getConsumerKey(), authCodeConfig.getConsumerSecret()).tokenUrl(authCodeConfig.getAccessTokenUrl()).responseExpiresInExpr(grantType.getExpirationRegex()).responseRefreshTokenExpr(grantType.getRefreshTokenExpr()).responseAccessTokenExpr(grantType.getAccessTokenExpr()).resourceOwnerIdTransformer(ownerId -> ownerId + "-" + config.getOwnerConfigName());
String scopes = authCodeConfig.getScope().orElseGet(() -> grantType.getDefaultScope().orElse(null));
if (scopes != null) {
dancerBuilder.scopes(scopes);
}
HttpServer httpServer;
try {
httpServer = httpService.get().getServerFactory().lookup(callbackConfig.getListenerConfig());
} catch (ServerNotFoundException e) {
throw new MuleRuntimeException(createStaticMessage(format("Connector '%s' defines '%s' as the http:listener-config to use for provisioning callbacks, but no such definition " + "exists in the application configuration", config.getOwnerConfigName(), callbackConfig.getListenerConfig())), e);
}
dancerBuilder.localCallback(httpServer, callbackConfig.getCallbackPath()).externalCallbackUrl(getExternalCallback(httpServer, callbackConfig)).authorizationUrl(authCodeConfig.getAuthorizationUrl()).localAuthorizationUrlPath(callbackConfig.getLocalAuthorizePath()).localAuthorizationUrlResourceOwnerId("#[attributes.queryParams.resourceOwnerId]").state("#[attributes.queryParams.state]").customParameters(config.getCustomParameters()).customParametersExtractorsExprs(getParameterExtractors(config));
Pair<Optional<Flow>, Optional<Flow>> listenerFlows = getListenerFlows(config);
listenerFlows.getFirst().ifPresent(flow -> dancerBuilder.beforeDanceCallback(beforeCallback(config, flow)));
listenerFlows.getSecond().ifPresent(flow -> dancerBuilder.afterDanceCallback(afterCallback(config, flow)));
AuthorizationCodeOAuthDancer dancer = dancerBuilder.build();
if (started) {
start(dancer);
}
return dancer;
}
use of org.mule.runtime.extension.api.connectivity.oauth.AuthorizationCodeGrantType in project mule by mulesoft.
the class ConnectionProviderModelLoaderDelegate method parseOAuthGrantType.
private void parseOAuthGrantType(ConnectionProviderElement providerType, ConnectionProviderDeclarer providerDeclarer) {
providerType.getAnnotation(AuthorizationCode.class).ifPresent(a -> {
AuthorizationCodeGrantType grantType = new AuthorizationCodeGrantType(a.accessTokenUrl(), a.authorizationUrl(), a.accessTokenExpr(), a.expirationExpr(), a.refreshTokenExpr(), a.defaultScopes());
providerDeclarer.withModelProperty(new OAuthModelProperty(asList(grantType)));
});
}
Aggregations