Exemplo n.º 1
0
  private static UserInfo getUserInfo(
      final OIDCProviderMetadata providerConfiguration, final BearerAccessToken bearerAccessToken)
      throws ParseException, SerializeException, IOException {
    final UserInfoRequest userInfoRequest =
        new UserInfoRequest(providerConfiguration.getUserInfoEndpointURI(), bearerAccessToken);

    UserInfoResponse userInfoResponse;

    switch (providerConfiguration.getIssuer().getValue()) {
      case ISSUER_FACEBOOK:
        userInfoResponse = FacebookUserInfoResponse.parse(userInfoRequest.toHTTPRequest().send());
        break;
      case ISSUER_PAY_PAL:
        userInfoResponse = PayPalUserInfoResponse.parse(userInfoRequest.toHTTPRequest().send());
        break;
      case ISSUER_MICROSOFT:
        userInfoResponse = MicrosoftUserInfoResponse.parse(userInfoRequest.toHTTPRequest().send());
        break;
      default: // Google.
        userInfoResponse = UserInfoResponse.parse(userInfoRequest.toHTTPRequest().send());
        break;
    }

    if (userInfoResponse instanceof UserInfoErrorResponse) {
      final ErrorObject error = ((UserInfoErrorResponse) userInfoResponse).getErrorObject();
      throw new GNUOpenBusinessApplicationException(error.getDescription());
    }

    return ((UserInfoSuccessResponse) userInfoResponse).getUserInfo();
  }
Exemplo n.º 2
0
 public static AuthenticationRequest getAuthenticationRequest(
     final OIDCProviderMetadata providerConfiguration,
     final URI issuerURI,
     final ClientID clientID,
     final URI redirectURI,
     Scope scope,
     State state) {
   return new AuthenticationRequest(
       providerConfiguration.getAuthorizationEndpointURI(),
       new ResponseType(ResponseType.Value.CODE),
       scope,
       clientID,
       redirectURI,
       state,
       new Nonce());
 }
Exemplo n.º 3
0
  public static OIDCProviderMetadata getProviderConfigurationURL(final URI issuerURI) {
    try {
      final URL providerConfigurationURL = issuerURI.toURL();
      final InputStream inputStream = providerConfigurationURL.openStream();

      String providerInfo = null;

      try (java.util.Scanner json = new java.util.Scanner(inputStream)) {
        providerInfo = json.useDelimiter("\\A").hasNext() ? json.next() : "";
      }

      return OIDCProviderMetadata.parse(providerInfo);
    } catch (ParseException | IOException e) {
      throw new GNUOpenBusinessApplicationException("Couldn't get OIDCProviderMetadata", e);
    }
  }
Exemplo n.º 4
0
  private static BearerAccessToken getTokenRequest(
      final OIDCProviderMetadata providerConfiguration,
      final ClientID clientID,
      final AuthorizationCode authorizationCode,
      final URI redirectURI,
      Secret clientSecret)
      throws SerializeException, ParseException, IOException, NoSuchAlgorithmException,
          InvalidKeySpecException, java.text.ParseException, JOSEException {
    final SecretTokenRequest tokenRequest =
        new SecretTokenRequest(
            providerConfiguration.getTokenEndpointURI(),
            clientID,
            clientSecret,
            new AuthorizationCodeGrant(authorizationCode, redirectURI));
    final TokenResponse tokenResponse =
        OIDCTokenResponseParser.parse(tokenRequest.toHTTPRequest().send());

    if (tokenResponse instanceof TokenErrorResponse) {
      final ErrorObject error = ((TokenErrorResponse) tokenResponse).getErrorObject();
      throw new GNUOpenBusinessApplicationException(error.getDescription());
    }

    return ((OIDCAccessTokenResponse) tokenResponse).getBearerAccessToken();
  }