Esempio n. 1
0
  public OAuthJSONAccessTokenResponse getAccessToken(HttpServletRequest request)
      throws FcConnectException {

    try {
      OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);

      log.debug("autorization code" + oar.getCode());

      // vérification a rajouter par rapport au state pour éviter le man in the middle
      //			if (StringUtils.isBlank(stateResponse) ||
      //					!stateResponse.equals(stateFromSession)) {
      //
      //				res = Response.ok("<p>Erreur de verif state response !!</p>",TEXT_HTML);
      //				addCORSOrigin(servletContext,res, headers);
      //		    	return res.build();
      ////				return new RedirectView("/login");
      //			}

      // récupération de l'access token
      OAuthClientRequest authClientRequest =
          OAuthClientRequest.tokenLocation(configuration.getTokenUri())
              .setGrantType(GrantType.AUTHORIZATION_CODE)
              .setClientId(configuration.getClientId())
              .setClientSecret(configuration.getClientSecret())
              .setRedirectURI(configuration.getRedirectUri())
              .setCode(oar.getCode())
              .buildBodyMessage();

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

      return oAuthClient.accessToken(authClientRequest);

    } catch (OAuthSystemException e) {
      throw new FcConnectException("Error during request for accessToken : ", e);
    } catch (OAuthProblemException e) {
      throw new FcConnectException("Error during accessToken retrieving : ", e);
    }
  }
Esempio n. 2
0
  public URI getRedirectUri() throws FcConnectException {

    try {
      OAuthClientRequest request =
          OAuthClientRequest.authorizationLocation(configuration.getAuthorizationUri())
              .setClientId(configuration.getClientId())
              .setRedirectURI(configuration.getRedirectUri())
              .setResponseType(ResponseType.CODE.toString())
              .setScope(configuration.getScope())
              .setState(configuration.getState())
              .setParameter(
                  configuration.getVerifParameterId(), configuration.getVerifParameterValue())
              .buildQueryMessage();

      log.debug(request.getLocationUri());

      return new URI(request.getLocationUri());

    } catch (OAuthSystemException e) {
      throw new FcConnectException(e);
    } catch (URISyntaxException e) {
      throw new FcConnectException("The uri is not well formed", e);
    }
  }