Search in sources :

Example 1 with AuthenticationRequestBuilder

use of org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder in project components by Talend.

the class Oauth2ImplicitClient method getAuthorizationCode.

private String getAuthorizationCode() {
    try {
        AuthenticationRequestBuilder builder = OAuthClientRequest.authorizationLocation(authorizationLocation.toString()).setClientId(clientID).setRedirectURI(callbackURL.toString());
        if (responseType != null) {
            builder.setResponseType(responseType);
        }
        OAuthClientRequest request = builder.buildQueryMessage();
        // FIXME : remove those Syso when the studio activate the INFO log by default
        System.out.println(messages.getMessage("msg.info.showAuthorizUrl"));
        System.out.println(request.getLocationUri());
        // --
        logger.info(messages.getMessage("msg.info.showAuthorizUrl"));
        logger.info(request.getLocationUri());
        OAuth2ImplicitGrantServer service = new OAuth2ImplicitGrantServer(callbackURL.getHost(), callbackURL.getPort(), 10 * 60 * 1000);
        // <--- this method wait for 10 minutes maximum to grab authorization code
        service.run();
        String code = service.getAuthorizationCode();
        service.stop();
        return code;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AuthenticationRequestBuilder(org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder) OAuth2ImplicitGrantServer(org.talend.components.common.oauth.server.OAuth2ImplicitGrantServer) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest) OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException)

Aggregations

OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)1 AuthenticationRequestBuilder (org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder)1 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)1 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)1 OAuth2ImplicitGrantServer (org.talend.components.common.oauth.server.OAuth2ImplicitGrantServer)1