Package com.google.api.client.googleapis.auth.oauth2

Examples of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequestTest


        try {
            HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
            BufferedReader br = new BufferedReader(new StringReader(gccCredential.getServiceAccountPrivateKey()));
            Security.addProvider(new BouncyCastleProvider());
            KeyPair kp = (KeyPair) new PEMReader(br).readObject();
            GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
                    .setJsonFactory(JSON_FACTORY)
                    .setServiceAccountId(gccCredential.getServiceAccountId())
                    .setServiceAccountScopes(SCOPES)
                    .setServiceAccountPrivateKey(kp.getPrivate())
                    .build();
View Full Code Here


  */
  public GoogleDriveSession(String clientId, String clientSecret, String refreshToken)
    throws IOException, GeneralSecurityException {
    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

    GoogleCredential credentials = new GoogleCredential.Builder().setClientSecrets(clientId, clientSecret)
        .setJsonFactory(JSON_FACTORY).setTransport(HTTP_TRANSPORT).build().setRefreshToken(refreshToken);

    drive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credentials).setApplicationName(APPNAME).build();
  }
View Full Code Here

   */
  @Test
  public void testGoldenSoap_oauth2() throws Exception {
    testHttpServer.setMockResponseBody(SoapResponseXmlProvider.getTestSoapResponse(API_VERSION));

    GoogleCredential credential = new GoogleCredential.Builder().setTransport(
        new NetHttpTransport()).setJsonFactory(new JacksonFactory()).build();
    credential.setAccessToken("TEST_ACCESS_TOKEN");

    DfpSession session = new DfpSession.Builder().withApplicationName("TEST_APP")
        .withOAuth2Credential(credential)
        .withEndpoint(testHttpServer.getServerUrl())
        .withNetworkCode("TEST_NETWORK_CODE")
View Full Code Here

        authorizationFlow.newTokenRequest(authorizationCode);
    tokenRequest.setRedirectUri(CALLBACK_URL);
    GoogleTokenResponse tokenResponse = tokenRequest.execute();

    // Create the OAuth2 credential.
    GoogleCredential credential = new GoogleCredential.Builder()
        .setTransport(new NetHttpTransport())
        .setJsonFactory(new JacksonFactory())
        .setClientSecrets(clientSecrets)
        .build();

    // Set authorized credentials.
    credential.setFromTokenResponse(tokenResponse);

    return credential;
  }
View Full Code Here

        authorizationFlow.newTokenRequest(authorizationCode);
    tokenRequest.setRedirectUri(CALLBACK_URL);
    GoogleTokenResponse tokenResponse = tokenRequest.execute();

    // Create the OAuth2 credential.
    GoogleCredential credential = new GoogleCredential.Builder()
        .setTransport(new NetHttpTransport())
        .setJsonFactory(new JacksonFactory())
        .setClientSecrets(clientSecrets)
        .build();

    // Set authorized credentials.
    credential.setFromTokenResponse(tokenResponse);

    return credential;
  }
View Full Code Here

    testHttpServer.setMockResponseBodies(Lists.newArrayList(
        SoapResponseXmlProvider.getTestTokenExpiredResponse(API_VERSION),
        SoapResponseXmlProvider.getTestAuthenticateResponse(API_VERSION, REGENERATED_TOKEN),
        SoapResponseXmlProvider.getTestSoapResponse(API_VERSION)));

    GoogleCredential credential = new GoogleCredential.Builder().setTransport(
        new NetHttpTransport()).setJsonFactory(new JacksonFactory()).build();
    credential.setAccessToken(OAUTH_ACCESS_TOKEN);

    DfaSession session = new DfaSession.Builder()
        .withUsernameAndOAuth2Credential("TEST_USERNAME", credential)
        .withApplicationName("TEST_APP")
        .withEndpoint(testHttpServer.getServerUrl())
View Full Code Here

   *
   * @return a newly refreshed offline credential.
   * @throws OAuthException if the credential could not be refreshed.
   */
  public Credential generateCredential() throws OAuthException {
    GoogleCredential credential = new GoogleCredential.Builder()
        .setTransport(httpTransport)
        .setJsonFactory(new JacksonFactory())
        .setClientSecrets(clientId, clientSecret)
        .setTokenServerEncodedUrl(tokenServerUrl)
        .build();
    credential.setRefreshToken(refreshToken);
    try {
      if (!oAuth2Helper.callRefreshToken(credential)) {
        throw new OAuthException(
            "Credential could not be refreshed. A newly generated refresh token may be required.");
      }
View Full Code Here

  private static final String CLIENT_ID = "myClientId";
  private static final String ANOTHER_CLIENT_ID = "anotherClientId";
  private static final String EMAIL_VERIFIED_KEY = "email_verified";

  private static Payload newPayload(String userId, String clientId) {
    Payload payload = new Payload();
    payload.setIssuer("accounts.google.com");
    payload.setAudience(clientId);
    payload.setAuthorizedParty(clientId);
    payload.setSubject(userId);
    payload.setExpirationTimeSeconds(100L);
    payload.setIssuedAtTimeSeconds(0L);
    return payload;
  }
View Full Code Here

    return payload;
  }

  @SuppressWarnings("deprecation")
  public void testDeprecatedMethods() {
    Payload payload = newPayload(USER_ID, CLIENT_ID);
    assertEquals(USER_ID, payload.getUserId());
    assertEquals(CLIENT_ID, payload.getIssuee());

    payload.setUserId(ANOTHER_USER_ID);
    payload.setIssuee(ANOTHER_CLIENT_ID);
    assertEquals(ANOTHER_USER_ID, payload.getUserId());
    assertEquals(ANOTHER_CLIENT_ID, payload.getIssuee());
    assertEquals(ANOTHER_USER_ID, payload.getSubject());
    assertEquals(ANOTHER_CLIENT_ID, payload.getAuthorizedParty());
  }
View Full Code Here

    assertEquals(ANOTHER_USER_ID, payload.getSubject());
    assertEquals(ANOTHER_CLIENT_ID, payload.getAuthorizedParty());
  }

  public void testEmailVerified() {
    Payload payload = newPayload(USER_ID, CLIENT_ID);
    assertNull(payload.getEmailVerified());

    payload.setEmailVerified(true);
    assertTrue(payload.getEmailVerified());

    payload.setEmailVerified(false);
    assertFalse(payload.getEmailVerified());

    payload.setEmailVerified(null);
    assertNull(payload.getEmailVerified());

    payload.set(EMAIL_VERIFIED_KEY, "true");
    assertTrue(payload.getEmailVerified());

    payload.set(EMAIL_VERIFIED_KEY, true);
    assertTrue(payload.getEmailVerified());

    payload.set(EMAIL_VERIFIED_KEY, "false");
    assertFalse(payload.getEmailVerified());

    payload.set(EMAIL_VERIFIED_KEY, false);
    assertFalse(payload.getEmailVerified());

    payload.set(EMAIL_VERIFIED_KEY, "RandomString");
    assertFalse(payload.getEmailVerified());

    payload.set(EMAIL_VERIFIED_KEY, "");
    assertFalse(payload.getEmailVerified());

    payload.set(EMAIL_VERIFIED_KEY, null);
    assertNull(payload.getEmailVerified());

    // Wrong type.
    payload.set(EMAIL_VERIFIED_KEY, new Integer(5));
    try {
      payload.getEmailVerified();
      fail();
    } catch (ClassCastException e) {
      // Expected.
    }
  }
View Full Code Here

TOP

Related Classes of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequestTest

Copyright © 2018 www.massapicom. 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.