Java Code Examples for com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver#getRedirectUri()

The following examples show how to use com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver#getRedirectUri() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageImportTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequiredPackagesImported() throws IOException {
  LocalServerReceiver codeReceiver = new LocalServerReceiver();
  String redirectUri = codeReceiver.getRedirectUri();
  URLConnection connection = new URL(redirectUri).openConnection();
  connection.setDoOutput(true);
  try (OutputStream outputStream = connection.getOutputStream();
      InputStreamReader reader = new InputStreamReader(connection.getInputStream())) {
    outputStream.write("hello".getBytes(StandardCharsets.UTF_8));
    StringBuilder response = new StringBuilder();
    char[] buffer = new char[1024];
    while (reader.read(buffer) != -1) {
      response.append(buffer);
    }
    assertThat(response.toString(), containsString("OAuth 2.0 Authentication Token Received"));
  }
}
 
Example 2
Source File: LoginServiceUi.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public VerificationCodeHolder obtainVerificationCodeFromExternalUserInteraction(String message) {
  LocalServerReceiver codeReceiver = createLocalServerReceiver();

  try {
    String redirectUrl = codeReceiver.getRedirectUri();
    if (!Program.launch(GoogleLoginService.getGoogleLoginUrl(redirectUrl))) {
      showErrorDialogHelper(
          Messages.getString("LOGIN_ERROR_DIALOG_TITLE"),
          Messages.getString("LOGIN_ERROR_CANNOT_OPEN_BROWSER"));
      return null;
    }

    String authorizationCode = showProgressDialogAndWaitForCode(codeReceiver);
    if (authorizationCode != null) {
      AnalyticsPingManager.getInstance().sendPingOnShell(shellProvider.getShell(),
          AnalyticsEvents.LOGIN_SUCCESS);

      return new VerificationCodeHolder(authorizationCode, redirectUrl);
    }
    return null;

  } catch (IOException ioe) {
    showErrorDialogHelper(Messages.getString("LOGIN_ERROR_DIALOG_TITLE"),
        Messages.getString("LOGIN_ERROR_LOCAL_SERVER_RUN", ioe.getLocalizedMessage()));
    return null;
  } finally {
    stopLocalServerReceiver(codeReceiver);
  }
}
 
Example 3
Source File: LoginServiceUiTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoginSuccessPage() throws IOException {
  LocalServerReceiver server = LoginServiceUi.createLocalServerReceiver();
  try {
    String localServerUrl = server.getRedirectUri();
    String landingPageUrl = simulateLogin(localServerUrl + "?code=success-simulated");
    assertEquals("https://cloud.google.com/eclipse/auth_success", landingPageUrl);
  } finally {
    server.stop();
  }
}
 
Example 4
Source File: LoginServiceUiTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoginFailurePage() throws IOException {
  LocalServerReceiver server = LoginServiceUi.createLocalServerReceiver();
  try {
    String localServerUrl = server.getRedirectUri();
    String landingPageUrl = simulateLogin(localServerUrl + "?error=simulated");
    assertEquals("https://cloud.google.com/eclipse/auth_failure", landingPageUrl);
  } finally {
    server.stop();
  }
}