org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder Java Examples

The following examples show how to use org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiClient.java    From eve-esi with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in
 * the apiAuthorizations (there should be only one)
 *
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
    for (Authentication apiAuth : authentications.values()) {
        if (apiAuth instanceof RetryingOAuth) {
            RetryingOAuth retryingOAuth = (RetryingOAuth) apiAuth;
            return retryingOAuth.getTokenRequestBuilder();
        }
    }
    return null;
}
 
Example #2
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
  for(Interceptor apiAuthorization : apiAuthorizations.values()) {
    if (apiAuthorization instanceof OAuth) {
      OAuth oauth = (OAuth) apiAuthorization;
      return oauth.getTokenRequestBuilder();
    }
  }
  return null;
}
 
Example #3
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
  for(RequestInterceptor apiAuthorization : apiAuthorizations.values()) {
    if (apiAuthorization instanceof OAuth) {
      OAuth oauth = (OAuth) apiAuthorization;
      return oauth.getTokenRequestBuilder();
    }
  }
  return null;
}
 
Example #4
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
 *
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
    for (Authentication apiAuth : authentications.values()) {
        if (apiAuth instanceof RetryingOAuth) {
            RetryingOAuth retryingOAuth = (RetryingOAuth) apiAuth;
            return retryingOAuth.getTokenRequestBuilder();
        }
    }
    return null;
}
 
Example #5
Source File: ApiClient.java    From android with MIT License 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
  for(Interceptor apiAuthorization : apiAuthorizations.values()) {
    if (apiAuthorization instanceof OAuth) {
      OAuth oauth = (OAuth) apiAuthorization;
      return oauth.getTokenRequestBuilder();
    }
  }
  return null;
}
 
Example #6
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
  for(Interceptor apiAuthorization : apiAuthorizations.values()) {
    if (apiAuthorization instanceof OAuth) {
      OAuth oauth = (OAuth) apiAuthorization;
      return oauth.getTokenRequestBuilder();
    }
  }
  return null;
}
 
Example #7
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
 *
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
    for (Authentication apiAuth : authentications.values()) {
        if (apiAuth instanceof RetryingOAuth) {
            RetryingOAuth retryingOAuth = (RetryingOAuth) apiAuth;
            return retryingOAuth.getTokenRequestBuilder();
        }
    }
    return null;
}
 
Example #8
Source File: ApiClient.java    From docusign-java-client with MIT License 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the authentications (there should be only one)
 * @return
 */
public TokenRequestBuilder getTokenEndPoint() {
  for(Authentication auth : getAuthentications().values()) {
    if (auth instanceof OAuth) {
      OAuth oauth = (OAuth) auth;
      return oauth.getTokenRequestBuilder();
    }
  }
  return null;
}
 
Example #9
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
  for(Interceptor apiAuthorization : apiAuthorizations.values()) {
    if (apiAuthorization instanceof OAuth) {
      OAuth oauth = (OAuth) apiAuthorization;
      return oauth.getTokenRequestBuilder();
    }
  }
  return null;
}
 
Example #10
Source File: OAuth.java    From android with MIT License 4 votes vote down vote up
public OAuth(TokenRequestBuilder requestBuilder ) {
    this(new OkHttpClient(), requestBuilder);
}
 
Example #11
Source File: OAuth.java    From docusign-java-client with MIT License 4 votes vote down vote up
public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) {
	this.tokenRequestBuilder = tokenRequestBuilder;
}
 
Example #12
Source File: OAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public OAuth(TokenRequestBuilder requestBuilder ) {
    this(new OkHttpClient(), requestBuilder);
}
 
Example #13
Source File: OAuth.java    From docusign-java-client with MIT License 4 votes vote down vote up
public TokenRequestBuilder getTokenRequestBuilder() {
	return tokenRequestBuilder;
}
 
Example #14
Source File: OAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public TokenRequestBuilder getTokenRequestBuilder() {
    return tokenRequestBuilder;
}
 
Example #15
Source File: OAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) {
    this.tokenRequestBuilder = tokenRequestBuilder;
}
 
Example #16
Source File: OAuth.java    From docusign-java-client with MIT License 4 votes vote down vote up
public OAuth(Client client, TokenRequestBuilder tokenRequestBuilder, AuthenticationRequestBuilder authenticationRequestBuilder) {
	this.oauthClient = new OAuthClient(new OAuthJerseyClient(client));
	this.tokenRequestBuilder = tokenRequestBuilder;
	this.authenticationRequestBuilder = authenticationRequestBuilder;
}
 
Example #17
Source File: OAuth.java    From android with MIT License 4 votes vote down vote up
public OAuth( OkHttpClient client, TokenRequestBuilder requestBuilder ) {
    this.oauthClient = new OAuthClient(new OAuthOkHttpClient(client));
    this.tokenRequestBuilder = requestBuilder;
}
 
Example #18
Source File: RetryingOAuth.java    From eve-esi with Apache License 2.0 4 votes vote down vote up
public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) {
    this.tokenRequestBuilder = tokenRequestBuilder;
}
 
Example #19
Source File: OAuth.java    From android with MIT License 4 votes vote down vote up
public TokenRequestBuilder getTokenRequestBuilder() {
    return tokenRequestBuilder;
}
 
Example #20
Source File: OAuth.java    From android with MIT License 4 votes vote down vote up
public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) {
    this.tokenRequestBuilder = tokenRequestBuilder;
}
 
Example #21
Source File: RetryingOAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public TokenRequestBuilder getTokenRequestBuilder() {
    return tokenRequestBuilder;
}
 
Example #22
Source File: RetryingOAuth.java    From eve-esi with Apache License 2.0 4 votes vote down vote up
public RetryingOAuth(OkHttpClient client, TokenRequestBuilder tokenRequestBuilder) {
    this.oAuthClient = new OAuthClient(new OAuthOkHttpClient(client));
    this.tokenRequestBuilder = tokenRequestBuilder;
}
 
Example #23
Source File: RetryingOAuth.java    From eve-esi with Apache License 2.0 4 votes vote down vote up
public RetryingOAuth(TokenRequestBuilder tokenRequestBuilder) {
    this(new OkHttpClient(), tokenRequestBuilder);
}
 
Example #24
Source File: OAuthTokenHandler.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
@Override
public Object execute(Req req) throws Exception {
	String code = req.param("code");
	String state = req.param("state");

	Log.debug("Received OAuth code", "code", code, "state", state);

	if (code != null && !U.isEmpty(state)) {

		String id = clientId.str().get();
		String secret = clientSecret.str().get();

		char statePrefix = state.charAt(0);
		U.must(statePrefix == 'P' || statePrefix == 'N', "Invalid OAuth state prefix!");
		state = state.substring(1);

		U.must(stateCheck.isValidState(state, secret, req.sessionId()), "Invalid OAuth state!");

		boolean popup = statePrefix == 'P';
		Log.debug("OAuth validated", "popup", popup);

		String domain = oauthDomain.getOrNull();
		String redirectUrl = U.notEmpty(domain) ? domain + callbackPath : HttpUtils.constructUrl(req, callbackPath);

		TokenRequestBuilder reqBuilder = OAuthClientRequest.tokenLocation(provider.getTokenEndpoint())
			.setGrantType(GrantType.AUTHORIZATION_CODE)
			.setClientId(id)
			.setClientSecret(secret)
			.setRedirectURI(redirectUrl)
			.setCode(code);

		OAuthClientRequest request = paramsInBody() ? reqBuilder.buildBodyMessage() : reqBuilder.buildBodyMessage();

		OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

		String accessToken = token(request, oAuthClient);

		String profileUrl = Msc.fillIn(provider.getProfileEndpoint(), "token", accessToken);

		OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(profileUrl).setAccessToken(
			accessToken).buildQueryMessage();

		OAuthResourceResponse res = oAuthClient.resource(bearerClientRequest,
			org.apache.oltu.oauth2.common.OAuth.HttpMethod.GET, OAuthResourceResponse.class);

		U.must(res.getResponseCode() == 200, "OAuth response error!");

		Map<String, Object> auth = JSON.parseMap(res.getBody());

		String email = (String) U.or(auth.get("email"), auth.get("emailAddress"));
		String firstName = (String) U.or(auth.get("firstName"), U.or(auth.get("first_name"), auth.get("given_name")));
		String lastName = (String) U.or(auth.get("lastName"), U.or(auth.get("last_name"), auth.get("family_name")));
		String name = U.or((String) auth.get("name"), firstName + " " + lastName);

		String username = email;
		Set<String> roles = customization.rolesProvider().getRolesForUser(req, username);

		UserInfo user = new UserInfo(username, roles);
		user.name = name;
		user.email = email;
		user.oauthProvider = provider.getName();
		user.oauthId = String.valueOf(auth.get("id"));

		req.response().authorize(user);

		return req.response().redirect("/");

	} else {
		String error = req.param("error");
		if (error != null) {
			Log.warn("OAuth error", "error", error);
			throw U.rte("OAuth error!");
		}
	}

	throw U.rte("Invalid OAuth request!");
}
 
Example #25
Source File: RetryingOAuth.java    From eve-esi with Apache License 2.0 4 votes vote down vote up
public TokenRequestBuilder getTokenRequestBuilder() {
    return tokenRequestBuilder;
}
 
Example #26
Source File: RetryingOAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public TokenRequestBuilder getTokenRequestBuilder() {
    return tokenRequestBuilder;
}
 
Example #27
Source File: OAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public OAuth(Client client, TokenRequestBuilder requestBuilder) {
    this.oauthClient = new OAuthClient(new OAuthFeignClient(client));
    this.tokenRequestBuilder = requestBuilder;
}
 
Example #28
Source File: OAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public TokenRequestBuilder getTokenRequestBuilder() {
    return tokenRequestBuilder;
}
 
Example #29
Source File: OAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) {
    this.tokenRequestBuilder = tokenRequestBuilder;
}
 
Example #30
Source File: OAuth.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public OAuth( OkHttpClient client, TokenRequestBuilder requestBuilder ) {
    this.oauthClient = new OAuthClient(new OAuthOkHttpClient(client));
    this.tokenRequestBuilder = requestBuilder;
}