Examples of TokenRequest


Examples of org.jclouds.oauth.v2.domain.TokenRequest

      return OAuthTestUtils.defaultProperties(super.setupProperties());
   }

   public void testGenerateJWTRequest() {
      OAuthApi api = requestSendsResponse(TOKEN_REQUEST, TOKEN_RESPONSE);
      assertEquals(api.authenticate(new TokenRequest(HEADER, CLAIM_SET)), TOKEN);
   }
View Full Code Here

Examples of org.jclouds.oauth.v2.domain.TokenRequest

   @Override
   public HttpRequest filter(HttpRequest request) throws HttpException {
      checkState(request instanceof GeneratedHttpRequest, "request must be an instance of GeneratedHttpRequest");
      GeneratedHttpRequest generatedHttpRequest = GeneratedHttpRequest.class.cast(request);
      TokenRequest tokenRequest = tokenRequestBuilder.apply(generatedHttpRequest);
      Token token = tokenFetcher.apply(tokenRequest);
      return request.toBuilder().addHeader("Authorization", String.format("%s %s",
              token.getTokenType(), token.getAccessToken())).build();

   }
View Full Code Here

Examples of org.jclouds.oauth.v2.domain.TokenRequest

              (OAuthTestUtils.defaultProperties(null)).build().utils()
              .injector().getInstance(TokenRequestFormat.class);
      Header header = new Header.Builder().signerAlgorithm("a").type("b").build();
      ClaimSet claimSet = new ClaimSet.Builder().addClaim("ist", STRING_THAT_GENERATES_URL_UNSAFE_BASE64_ENCODING)
              .build();
      TokenRequest tokenRequest = new TokenRequest.Builder().claimSet(claimSet).header(header).build();
      HttpRequest request = tokenRequestFormat.formatRequest(HttpRequest.builder().method("GET").endpoint
              ("http://localhost").build(), tokenRequest);

      assertNotNull(request.getPayload());
View Full Code Here

Examples of org.jclouds.oauth.v2.domain.TokenRequest

                                  .addClaim("scope", scopes)
                                  .addClaim("iss", identity)
                                  .emissionTime(now)
                                  .expirationTime(now + 3600).build();

      TokenRequest tokenRequest = TokenRequest.builder().header(header).claimSet(claimSet).build();

      Token token = oauthApi.authenticate(tokenRequest);

      assertNotNull(token, "no token when authenticating " + tokenRequest);
   }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.TokenRequest

    refreshToken = Mockito.mock(OAuth2RefreshTokenEntity.class);
    Mockito.when(tokenRepository.getRefreshTokenByValue(refreshTokenValue)).thenReturn(refreshToken);
    Mockito.when(refreshToken.getClient()).thenReturn(client);
    Mockito.when(refreshToken.isExpired()).thenReturn(false);

    tokenRequest = new TokenRequest(null, clientId, null, null);

    storedAuthentication = authentication;
    storedAuthRequest = clientAuth;
    storedAuthHolder = Mockito.mock(AuthenticationHolderEntity.class);
    storedScope = Sets.newHashSet(scope);
View Full Code Here

Examples of org.springframework.security.oauth2.provider.TokenRequest

    }

    String clientId = getClientId(principal);
    ClientDetails authenticatedClient = getClientDetailsService().loadClientByClientId(clientId);

    TokenRequest tokenRequest = getOAuth2RequestFactory().createTokenRequest(parameters, authenticatedClient);

    if (clientId != null && !clientId.equals("")) {
      // Only validate the client details if a client authenticated during this
      // request.
      if (!clientId.equals(tokenRequest.getClientId())) {
        // double check to make sure that the client ID in the token request is the same as that in the
        // authenticated client
        throw new InvalidClientException("Given client ID does not match authenticated client");
      }
    }
    if (authenticatedClient != null) {
      oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);
    }
    if (!StringUtils.hasText(tokenRequest.getGrantType())) {
      throw new InvalidRequestException("Missing grant type");
    }
    if (tokenRequest.getGrantType().equals("implicit")) {
      throw new InvalidGrantException("Implicit grant type not supported from token endpoint");
    }

    if (isAuthCodeRequest(parameters)) {
      // The scope was requested or determined during the authorization step
      if (!tokenRequest.getScope().isEmpty()) {
        logger.debug("Clearing scope of incoming token request");
        tokenRequest.setScope(Collections.<String> emptySet());
      }
    }

    if (isRefreshTokenRequest(parameters)) {
      // A refresh token has its own default scopes, so we should ignore any added by the factory here.
      tokenRequest.setScope(OAuth2Utils.parseParameterList(parameters.get(OAuth2Utils.SCOPE)));
    }

    OAuth2AccessToken token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
    if (token == null) {
      throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
    }

    return getResponse(token);

  }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.TokenRequest

      }
    }
    String grantType = requestParameters.get(OAuth2Utils.GRANT_TYPE);

    Set<String> scopes = extractScopes(requestParameters, clientId);
    TokenRequest tokenRequest = new TokenRequest(requestParameters, clientId, scopes, grantType);

    return tokenRequest;
  }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.TokenRequest

    return tokenRequest;
  }

  public TokenRequest createTokenRequest(AuthorizationRequest authorizationRequest, String grantType) {
    TokenRequest tokenRequest = new TokenRequest(authorizationRequest.getRequestParameters(),
        authorizationRequest.getClientId(), authorizationRequest.getScope(), grantType);
    return tokenRequest;
  }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.TokenRequest

  }

  // We can grant a token and return it with implicit approval.
  private ModelAndView getImplicitGrantResponse(AuthorizationRequest authorizationRequest) {
    try {
      TokenRequest tokenRequest = getOAuth2RequestFactory().createTokenRequest(authorizationRequest, "implicit");
      OAuth2Request storedOAuth2Request = getOAuth2RequestFactory().createOAuth2Request(authorizationRequest);
      OAuth2AccessToken accessToken = getAccessTokenForImplicitGrant(tokenRequest, storedOAuth2Request);
      if (accessToken == null) {
        throw new UnsupportedResponseTypeException("Unsupported response type: token");
      }
View Full Code Here

Examples of org.springframework.security.oauth2.provider.TokenRequest

  @Test(expected = InvalidGrantException.class)
  public void testRefreshedTokenInvalidWithWrongClient() throws Exception {
    ExpiringOAuth2RefreshToken expectedExpiringRefreshToken = (ExpiringOAuth2RefreshToken) getTokenServices()
        .createAccessToken(createAuthentication()).getRefreshToken();
    TokenRequest tokenRequest = new TokenRequest(Collections.singletonMap("client_id", "wrong"), "wrong", null,
        null);
    OAuth2AccessToken refreshedAccessToken = getTokenServices().refreshAccessToken(
        expectedExpiringRefreshToken.getValue(), tokenRequest);
    assertEquals("[read]", refreshedAccessToken.getScope().toString());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.