Search in sources :

Example 21 with Client

use of com.aliyun.ons20190214.Client in project service-proxy by membrane.

the class DynamicRegistration method registerWithCallbackAt.

public Client registerWithCallbackAt(String callbackUri, String registrationEndpoint) throws Exception {
    Exchange exc = new Request.Builder().post(registrationEndpoint).header(Header.CONTENT_TYPE, MimeType.APPLICATION_JSON_UTF8).body(getRegistrationBody(callbackUri)).buildExchange();
    Response response = doRequest(exc);
    HashMap<String, String> json = Util.parseSimpleJSONResponse(response);
    if (!json.containsKey("client_id") || !json.containsKey("client_secret"))
        throw new RuntimeException("Registration endpoint didn't return clientId/clientSecret");
    return new Client(json.get("client_id"), json.get("client_secret"), "");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) Client(com.predic8.membrane.core.interceptor.oauth2.Client) HttpClient(com.predic8.membrane.core.transport.http.HttpClient)

Example 22 with Client

use of com.aliyun.ons20190214.Client in project cloud-sdk by mizhousoft.

the class AliyunSendSmsClient method init.

public void init(AliyunSmsProfile profile) throws CloudSDKException {
    AssertUtils.notNull(profile.getAccessKeyId(), "Access key id is null.");
    AssertUtils.notNull(profile.getAccessKeySecret(), "Access key secret is null.");
    AssertUtils.notNull(profile.getEndpoint(), "Endpoint is null.");
    Config config = new Config().setAccessKeyId(profile.getAccessKeyId()).setAccessKeySecret(profile.getAccessKeySecret()).setEndpoint(profile.getEndpoint());
    try {
        this.client = new com.aliyun.dysmsapi20170525.Client(config);
    } catch (Exception e) {
        throw new CloudSDKException("Init sms client failed.", e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) Config(com.aliyun.teaopenapi.models.Config) Client(com.aliyun.dysmsapi20170525.Client) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException)

Example 23 with Client

use of com.aliyun.ons20190214.Client in project service-proxy by membrane.

the class PasswordFlow method processWithParameters.

@Override
protected Response processWithParameters() throws Exception {
    if (!verifyClientThroughParams())
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "unauthorized_client");
    Map<String, String> userParams = verifyUserThroughParams();
    if (userParams == null)
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "access_denied");
    scope = getScope();
    token = createTokenForVerifiedUserAndClient();
    refreshToken = authServer.getRefreshTokenGenerator().getToken(getUsername(), getClientId(), getClientSecret());
    SessionManager.Session session = createSessionForAuthorizedUserWithParams();
    synchronized (session) {
        session.getUserAttributes().put(ACCESS_TOKEN, token);
        session.getUserAttributes().putAll(userParams);
    }
    authServer.getSessionFinder().addSessionForToken(token, session);
    Client client;
    try {
        synchronized (authServer.getClientList()) {
            client = authServer.getClientList().getClient(getClientId());
        }
    } catch (Exception e) {
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_client");
    }
    String grantTypes = client.getGrantTypes();
    if (!grantTypes.contains(getGrantType())) {
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_grant_type");
    }
    refreshToken = authServer.getRefreshTokenGenerator().getToken(client.getClientId(), client.getClientId(), client.getClientSecret());
    if (authServer.isIssueNonSpecIdTokens() && OAuth2Util.isOpenIdScope(scope)) {
        idToken = createSignedIdToken(session, client.getClientId(), client);
    }
    exc.setResponse(getEarlyResponse());
    return new NoResponse();
}
Also used : SessionManager(com.predic8.membrane.core.interceptor.authentication.session.SessionManager) Client(com.predic8.membrane.core.interceptor.oauth2.Client) NoResponse(com.predic8.membrane.core.interceptor.oauth2.request.NoResponse) IOException(java.io.IOException) JoseException(org.jose4j.lang.JoseException)

Example 24 with Client

use of com.aliyun.ons20190214.Client in project service-proxy by membrane.

the class AuthWithoutSessionRequest method processWithParameters.

@Override
protected Response processWithParameters() throws Exception {
    Client client;
    try {
        client = authServer.getClientList().getClient(getClientId());
    } catch (Exception e) {
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "unauthorized_client");
    }
    if (!OAuth2Util.isAbsoluteUri(getRedirectUri()) || !getRedirectUri().equals(client.getCallbackUrl()))
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_request");
    if (promptEqualsNone())
        return createParameterizedFormUrlencodedRedirect(exc, getState(), client.getCallbackUrl() + "?error=login_required");
    if (!authServer.getSupportedAuthorizationGrants().contains(getResponseType()))
        return createParameterizedFormUrlencodedRedirect(exc, getState(), client.getCallbackUrl() + "?error=unsupported_response_type");
    String validScopes = verifyScopes(getScope());
    if (validScopes.isEmpty())
        return createParameterizedFormUrlencodedRedirect(exc, getState(), client.getCallbackUrl() + "?error=invalid_scope");
    if (OAuth2Util.isOpenIdScope(validScopes)) {
        if (!isCodeRequest())
            return createParameterizedFormUrlencodedRedirect(exc, getState(), client.getCallbackUrl() + "?error=invalid_request");
        // Parses the claims parameter into a json object. Claim values are always ignored and set to "null" as it is optional to react to those values
        addValidClaimsToParams();
    } else
        removeClaimsWhenNotOpenidScope();
    setScope(validScopes);
    String invalidScopes = hasGivenInvalidScopes(getScope(), validScopes);
    if (!invalidScopes.isEmpty())
        setScopeInvalid(invalidScopes);
    SessionManager.Session session = authServer.getSessionManager().getOrCreateSession(exc);
    addParams(session, params);
    return new NoResponse();
}
Also used : SessionManager(com.predic8.membrane.core.interceptor.authentication.session.SessionManager) Client(com.predic8.membrane.core.interceptor.oauth2.Client) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 25 with Client

use of com.aliyun.ons20190214.Client in project service-proxy by membrane.

the class DynamicRegistration method registerWithCallbackAt.

public Client registerWithCallbackAt(List<String> callbackUris, String registrationEndpoint) throws Exception {
    Exchange exc = new Request.Builder().post(registrationEndpoint).header(Header.CONTENT_TYPE, MimeType.APPLICATION_JSON_UTF8).body(getRegistrationBody(callbackUris)).buildExchange();
    Response response = doRequest(exc);
    HashMap<String, String> json = Util.parseSimpleJSONResponse(response);
    if (!json.containsKey("client_id") || !json.containsKey("client_secret"))
        throw new RuntimeException("Registration endpoint didn't return clientId/clientSecret");
    return new Client(json.get("client_id"), json.get("client_secret"), "", json.get("grant_types"));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) Client(com.predic8.membrane.core.interceptor.oauth2.Client) HttpClient(com.predic8.membrane.core.transport.http.HttpClient)

Aggregations

Client (org.orcid.jaxb.model.client_v2.Client)18 Test (org.junit.Test)13 Client (com.aliyun.dysmsapi20170525.Client)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 Client (com.predic8.membrane.core.interceptor.oauth2.Client)9 Config (com.aliyun.teaopenapi.models.Config)6 HashSet (java.util.HashSet)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)5 BaseTest (org.orcid.core.BaseTest)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 NoResponse (com.predic8.membrane.core.interceptor.oauth2.request.NoResponse)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)2 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)2 Client (com.aliyun.ons20190214.Client)2 OnsTopicListRequest (com.aliyun.ons20190214.models.OnsTopicListRequest)2 OnsTopicListResponse (com.aliyun.ons20190214.models.OnsTopicListResponse)2