Example usage for com.google.api.client.googleapis.auth.oauth2 GoogleOAuthConstants OOB_REDIRECT_URI

List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleOAuthConstants OOB_REDIRECT_URI

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.auth.oauth2 GoogleOAuthConstants OOB_REDIRECT_URI.

Prototype

String OOB_REDIRECT_URI

To view the source code for com.google.api.client.googleapis.auth.oauth2 GoogleOAuthConstants OOB_REDIRECT_URI.

Click Source Link

Document

Redirect URI to use for an installed application as specified in <a href="https://developers.google.com/identity/protocols/OAuth2InstalledApp">Using OAuth 2.0 for Mobile & Desktop Apps</a>.

Usage

From source file:com.cloudglomerate.connection.OAuth2Native.java

License:Apache License

/**
 * Authorizes the installed application to access user's protected data.
 *
 * @param transport HTTP transport//  w w  w .  ja  va2s .c  om
 * @param jsonFactory JSON factory
 * @param receiver verification code receiver
 * @param scopes OAuth 2.0 scopes
 */
public static GoogleResponse authorize(HttpTransport transport, JsonFactory jsonFactory,
        Iterable<String> scopes) {

    String redirectUri = GoogleOAuthConstants.OOB_REDIRECT_URI;
    GoogleClientSecrets clientSecrets = null;
    try {
        clientSecrets = loadClientSecrets(jsonFactory);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    GoogleResponse gResp = new GoogleResponse(Status.INITIATED, Cloud.GOOGLE);
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(transport, jsonFactory,
            clientSecrets, scopes).setAccessType("online").setApprovalPrompt("auto").build();

    gResp.setAuthCodeFlow(flow);

    String url = flow.newAuthorizationUrl().setRedirectUri(redirectUri).build();
    gResp.setURL(url);
    return gResp;
}

From source file:com.cloudglomerate.connection.OAuth2Native.java

License:Apache License

public static void getCredential(GoogleResponse resp) {
    String redirectUri = GoogleOAuthConstants.OOB_REDIRECT_URI;
    GoogleTokenResponse response = null;
    try {//www  .j  a va2s .  c om
        response = resp.getAuthCodeFlow().newTokenRequest(resp.getCode()).setRedirectUri(redirectUri).execute();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // store credential and return it
    try {
        resp.setCreds(resp.getAuthCodeFlow().createAndStoreCredential(response, null));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    resp.setStatus(Status.CONNECTED);
}

From source file:com.evolveum.polygon.connector.googleapps.Main.java

License:Open Source License

static Map<String, Object> getConfigurationMap(File clientJson)
        throws IOException, URISyntaxException, Exception {
    System.setProperty("https.protocols", "TLSv1.2");

    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new FileReader(clientJson));

    Credential credential = new AuthorizationCodeInstalledApp(
            new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                    .setAccessType("offline").setApprovalPrompt("force")
                    .setDataStoreFactory(MemoryDataStoreFactory.getDefaultInstance()).build(),
            new AbstractPromptReceiver() {
                @Override/* w ww .ja  va 2  s  . co  m*/
                public String getRedirectUri() throws IOException {
                    return GoogleOAuthConstants.OOB_REDIRECT_URI;
                }
            }).authorize("user");

    Map<String, Object> configMap = new LinkedHashMap<String, Object>(3);
    configMap.put("clientId", clientSecrets.getDetails().getClientId());
    configMap.put("clientSecret", clientSecrets.getDetails().getClientSecret());
    configMap.put("refreshToken", credential.getRefreshToken());
    return configMap;
}

From source file:com.singhanuvrat.experiment.googleapi.PromptReceiver.java

License:Apache License

public String getRedirectUri() {
    return GoogleOAuthConstants.OOB_REDIRECT_URI;
}

From source file:de.quaddy_services.deadlinereminder.extern.PromptReceiver.java

License:Apache License

@Override
public String getRedirectUri() {
    return GoogleOAuthConstants.OOB_REDIRECT_URI;
}

From source file:javamailclient.GmailAPI.java

public static void initialize(String code) throws IOException {
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    clientSecrets = GoogleClientSecrets.load(jsonFactory, new FileReader(CLIENT_SECRET_PATH));

    // Allow user to authorize via url.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory,
            clientSecrets, Arrays.asList(SCOPE)).setAccessType("online").setApprovalPrompt("auto").build();

    String url = flow.newAuthorizationUrl().setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI).build();
    //System.out.println("Please open the following URL in your browser then type"+" the authorization code:\n" + url);

    // Read code entered by user.
    //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    //String code = br.readLine();

    // Generate Credential using retrieved code.
    GoogleTokenResponse response = flow.newTokenRequest(code)
            .setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI).execute();
    GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response);

    // Create a new authorized Gmail API client
    service = new Gmail.Builder(httpTransport, jsonFactory, credential).setApplicationName(APP_NAME).build();

    Profile profile = service.users().getProfile(USER).execute();
    USER_EMAIL = profile.getEmailAddress();
    System.out.println(USER_EMAIL);
    /*ListThreadsResponse threadsResponse = service.users().threads().list(USER).execute();
    List<Thread> threads = threadsResponse.getThreads();
            //  www.ja v  a 2  s.c o m
    // Print ID of each Thread.
    for (Thread thread : threads) {
      System.out.println("Thread ID: " + thread.getId());
    }*/
}

From source file:me.emily.oauth2.OAuth2Native.java

License:Apache License

public Credential authorize(String code, Iterable<String> scopes) throws IOException {

    GoogleAuthorizationCodeFlow flow = startFlow(scopes);

    GoogleTokenResponse response = flow.newTokenRequest(code)
            .setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI).execute();

    log.info("/------------ Response ");
    log.info("|  Id: {}", response.getIdToken());
    log.info("|  Token: {}", response.getAccessToken());
    log.info("|  Refresh token: {}", response.getRefreshToken());
    log.info("|  Expiry: {}", response.getExpiresInSeconds());
    log.info("|  Type: {}", response.getTokenType());
    log.info("|  Scope: {}", response.getScope());
    for (Map.Entry<String, Object> entry : response.getUnknownKeys().entrySet()) {
        log.info("|  {}: {}", entry.getKey(), entry.getValue());
    }/*from ww  w.j a v  a 2  s  .co  m*/
    log.info("\\------------");

    Credential creds = flow.createAndStoreCredential(response, null);

    return creds;
}

From source file:net.tirasa.connid.bundles.googleapps.Main.java

License:Open Source License

static Map<String, Object> getConfigurationMap(File clientJson) throws IOException, URISyntaxException {

    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new FileReader(clientJson));

    Credential credential = new AuthorizationCodeInstalledApp(
            new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                    .setAccessType("offline").setApprovalPrompt("force")
                    .setDataStoreFactory(MemoryDataStoreFactory.getDefaultInstance()).build(),
            new AbstractPromptReceiver() {

                @Override//from w w  w  . j  a  v a2  s.  com
                public String getRedirectUri() throws IOException {
                    return GoogleOAuthConstants.OOB_REDIRECT_URI;
                }
            }).authorize("user");

    Map<String, Object> configMap = new LinkedHashMap<String, Object>(3);
    configMap.put("clientId", clientSecrets.getDetails().getClientId());
    configMap.put("clientSecret", clientSecrets.getDetails().getClientSecret());
    configMap.put("refreshToken", credential.getRefreshToken());
    return configMap;
}

From source file:org.forgerock.openicf.connectors.googleapps.Main.java

License:Open Source License

static Map<String, Object> getConfigurationMap(File clientJson) throws IOException, URISyntaxException {
    System.setProperty("https.protocols", "TLSv1.2");

    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new FileReader(clientJson));

    Credential credential = new AuthorizationCodeInstalledApp(
            new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                    .setAccessType("offline").setApprovalPrompt("force")
                    .setDataStoreFactory(MemoryDataStoreFactory.getDefaultInstance()).build(),
            new AbstractPromptReceiver() {
                @Override// w w  w .jav  a 2 s  .  com
                public String getRedirectUri() throws IOException {
                    return GoogleOAuthConstants.OOB_REDIRECT_URI;
                }
            }).authorize("user");

    Map<String, Object> configMap = new LinkedHashMap<String, Object>(3);
    configMap.put("clientId", clientSecrets.getDetails().getClientId());
    configMap.put("clientSecret", clientSecrets.getDetails().getClientSecret());
    configMap.put("refreshToken", credential.getRefreshToken());
    return configMap;
}

From source file:org.ut.biolab.medsavant.app.google.MedSavantPromptReceiver.java

@Override
public String getRedirectUri() throws IOException {
    return GoogleOAuthConstants.OOB_REDIRECT_URI;

}