コード例 #1
0
ファイル: OAuthTwoClient.java プロジェクト: lcallero/oauth2
  /**
   * This method will create {@code OAuthApplicationInfo} object from a Map of Attributes.
   *
   * @param responseMap Response returned from server as a Map
   * @return OAuthApplicationInfo object will return.
   */
  private OAuthApplicationInfo createOAuthAppfromResponse(Map responseMap) {

    // Sample response returned by client registration endpoint.
    // {"id":305,"creationDate":1430486098086,"modificationDate":1430486098086,"name":"TestClient_2",
    // "clientId":"testclient_2","secret":"3b4dbfb6-0ad9-403e-8ed6-715459fc8c78",
    // "description":null,"contactName":"John Doe","contactEmail":"*****@*****.**",
    // "scopes":["scope1"],"attributes":{},"thumbNailUrl":null,"redirectUris":[],
    // "skipConsent":false,"includePrincipal":false,"expireDuration":0,"useRefreshTokens":false,
    // "allowedImplicitGrant":false,"allowedClientCredentials":false}

    OAuthApplicationInfo info = new OAuthApplicationInfo();
    Object clientId = responseMap.get(OAuthTwoConstants.CLIENT_ID);
    info.setClientId((String) clientId);

    Object clientSecret = responseMap.get(OAuthTwoConstants.CLIENT_SECRET);
    info.setClientSecret((String) clientSecret);

    Object id = responseMap.get("id");
    info.addParameter("id", id);

    Object contactName = responseMap.get(OAuthTwoConstants.CLIENT_CONTACT_NAME);
    if (contactName != null) {
      info.addParameter("contactName", contactName);
    }

    Object contactMail = responseMap.get(OAuthTwoConstants.CLIENT_CONTAT_EMAIL);
    if (contactMail != null) {
      info.addParameter("contactMail", contactMail);
    }

    Object scopes = responseMap.get(OAuthTwoConstants.SCOPES);
    if (scopes != null) {
      info.addParameter("scopes", scopes);
    }

    return info;
  }