com.google.api.client.util.store.MemoryDataStoreFactory Java Examples
The following examples show how to use
com.google.api.client.util.store.MemoryDataStoreFactory.
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: OAuthAuthenticator.java From che with Eclipse Public License 2.0 | 6 votes |
/** * @see {@link #configure(String, String, String[], String, String, MemoryDataStoreFactory, List)} */ protected void configure( String clientId, String clientSecret, String[] redirectUris, String authUri, String tokenUri, MemoryDataStoreFactory dataStoreFactory) throws IOException { configure( clientId, clientSecret, redirectUris, authUri, tokenUri, dataStoreFactory, Collections.emptyList()); }
Example #2
Source File: AdvancedCreateCredentialFromScratch.java From googleads-java-lib with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { if (CLIENT_ID.equals("INSERT_CLIENT_ID_HERE") || CLIENT_SECRET.equals("INSERT_CLIENT_SECRET_HERE")) { throw new IllegalArgumentException( "Please input your client IDs or secret. " + "See https://console.developers.google.com/project"); } // It is highly recommended that you use a credential store in your // application to store a per-user Credential. // See: // https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#data_store DataStoreFactory storeFactory = new MemoryDataStoreFactory(); // Authorize and store your credential. authorize(storeFactory, USER_ID); // Create a AdManagerSession from the credential store. You will typically do this // in a servlet interceptor for a web application or per separate thread // of your offline application. AdManagerSession adManagerSession = createDfpSession(storeFactory, USER_ID); AdManagerServices adManagerServices = new AdManagerServices(); runExample(adManagerServices, adManagerSession); }
Example #3
Source File: GitHubOAuthAuthenticator.java From che with Eclipse Public License 2.0 | 6 votes |
@Inject public GitHubOAuthAuthenticator( @Nullable @Named("che.oauth.github.clientid") String clientId, @Nullable @Named("che.oauth.github.clientsecret") String clientSecret, @Nullable @Named("che.oauth.github.redirecturis") String[] redirectUris, @Nullable @Named("che.oauth.github.authuri") String authUri, @Nullable @Named("che.oauth.github.tokenuri") String tokenUri) throws IOException { if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && !isNullOrEmpty(authUri) && !isNullOrEmpty(tokenUri) && redirectUris != null && redirectUris.length != 0) { configure( clientId, clientSecret, redirectUris, authUri, tokenUri, new MemoryDataStoreFactory()); } }
Example #4
Source File: RedHatOAuthAuthenticator.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Inject public RedHatOAuthAuthenticator( @Nullable @Named("oauth.redhat.clientid") String clientId, @Nullable @Named("oauth.redhat.clientsecret") String clientSecret, @Nullable @Named("oauth.redhat.redirecturis") String[] redirectUris, @Nullable @Named("oauth.redhat.authuri") String authUri, @Nullable @Named("oauth.redhat.tokenuri") String tokenUri, @Nullable @Named("oauth.redhat.useruri") String userUri) throws IOException { if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && !isNullOrEmpty(authUri) && !isNullOrEmpty(tokenUri) && !isNullOrEmpty(userUri) && redirectUris != null && redirectUris.length != 0) { configure( clientId, clientSecret, redirectUris, authUri, tokenUri, new MemoryDataStoreFactory()); } this.userUri = userUri; }
Example #5
Source File: OpenShiftOAuthAuthenticator.java From che with Eclipse Public License 2.0 | 6 votes |
@Inject public OpenShiftOAuthAuthenticator( @Nullable @Named("che.oauth.openshift.clientid") String clientId, @Nullable @Named("che.oauth.openshift.clientsecret") String clientSecret, @Nullable @Named("che.oauth.openshift.oauth_endpoint") String oauthEndpoint, @Nullable @Named("che.oauth.openshift.verify_token_url") String verifyTokenUrl, @Named("che.api") String apiEndpoint) throws IOException { this.verifyTokenUrl = verifyTokenUrl; String[] redirectUrl = {apiEndpoint + "/oauth/callback"}; if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && !isNullOrEmpty(oauthEndpoint)) { oauthEndpoint = oauthEndpoint.endsWith("/") ? oauthEndpoint : oauthEndpoint + "/"; configure( clientId, clientSecret, redirectUrl, oauthEndpoint + "oauth/authorize", oauthEndpoint + "oauth/token", new MemoryDataStoreFactory()); } }
Example #6
Source File: OpenShiftGitHubOAuthAuthenticator.java From che with Eclipse Public License 2.0 | 6 votes |
@Inject public OpenShiftGitHubOAuthAuthenticator( @Nullable @Named("che.oauth.github.redirecturis") String[] redirectUris, @Nullable @Named("che.oauth.github.authuri") String authUri, @Nullable @Named("che.oauth.github.tokenuri") String tokenUri) throws IOException { super("NULL", "NULL", redirectUris, authUri, tokenUri); if (!isNullOrEmpty(authUri) && !isNullOrEmpty(tokenUri) && redirectUris != null && redirectUris.length != 0) { configure("NULL", "NULL", redirectUris, authUri, tokenUri, new MemoryDataStoreFactory()); } }
Example #7
Source File: ProjectLockerOAuthAuthenticator.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Inject public ProjectLockerOAuthAuthenticator( @Nullable @Named("oauth.projectlocker.clientid") String clientId, @Nullable @Named("oauth.projectlocker.clientsecret") String clientSecret, @Nullable @Named("oauth.projectlocker.redirecturis") String[] redirectUris, @Nullable @Named("oauth.projectlocker.authuri") String authUri, @Nullable @Named("oauth.projectlocker.tokenuri") String tokenUri) throws IOException { if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && !isNullOrEmpty(authUri) && !isNullOrEmpty(tokenUri) && redirectUris != null && redirectUris.length != 0) { configure( clientId, clientSecret, redirectUris, authUri, tokenUri, new MemoryDataStoreFactory()); } }
Example #8
Source File: BitbucketOAuthAuthenticator.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Inject public BitbucketOAuthAuthenticator( @Nullable @Named("oauth.bitbucket.clientid") String clientId, @Nullable @Named("oauth.bitbucket.clientsecret") String clientSecret, @Nullable @Named("oauth.bitbucket.redirecturis") String[] redirectUris, @Nullable @Named("oauth.bitbucket.useruri") String userUri, @Nullable @Named("oauth.bitbucket.authuri") String authUri, @Nullable @Named("oauth.bitbucket.tokenuri") String tokenUri) throws IOException { super(); if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && !isNullOrEmpty(authUri) && !isNullOrEmpty(tokenUri) && redirectUris != null && redirectUris.length != 0) { configure( clientId, clientSecret, redirectUris, authUri, tokenUri, new MemoryDataStoreFactory()); } this.userUri = userUri; }
Example #9
Source File: LinkedInOAuthAuthenticator.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Inject public LinkedInOAuthAuthenticator( @Nullable @Named("oauth.linkedin.clientid") String clientId, @Nullable @Named("oauth.linkedin.clientsecret") String clientSecret, @Nullable @Named("oauth.linkedin.redirecturis") String[] redirectUris, @Nullable @Named("oauth.linkedin.authuri") String authUri, @Nullable @Named("oauth.linkedin.tokenuri") String tokenUri, @Nullable @Named("oauth.linkedin.useruri") String userUri) throws IOException { if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && !isNullOrEmpty(authUri) && !isNullOrEmpty(tokenUri) && !isNullOrEmpty(userUri) && redirectUris != null && redirectUris.length != 0) { configure( clientId, clientSecret, redirectUris, authUri, tokenUri, new MemoryDataStoreFactory()); } this.userUri = userUri; }
Example #10
Source File: MicrosoftOauthAuthenticator.java From codenvy with Eclipse Public License 1.0 | 5 votes |
@Inject public MicrosoftOauthAuthenticator( @Nullable @Named("oauth.microsoft.clientid") String clientId, @Nullable @Named("oauth.microsoft.clientsecret") String clientSecret, @Nullable @Named("oauth.microsoft.redirecturis") String[] redirectUris, @Nullable @Named("oauth.microsoft.authuri") String authUri, @Nullable @Named("oauth.microsoft.tokenuri") String tokenUri, @Nullable @Named("oauth.microsoft.useruri") String userUri) throws IOException { if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && !isNullOrEmpty(authUri) && !isNullOrEmpty(tokenUri) && !isNullOrEmpty(userUri) && redirectUris != null && redirectUris.length != 0) { configure( new MicrosoftAuthorizationCodeFlow.Builder( BearerToken.authorizationHeaderAccessMethod(), new NetHttpTransport(), new JacksonFactory(), new GenericUrl(tokenUri), new MicrosoftParametersAuthentication(clientSecret), clientId, authUri) .setScopes(Arrays.asList("vso.code_manage", "vso.code_status")) .setDataStoreFactory(new MemoryDataStoreFactory()) .build(), Arrays.asList(redirectUris)); } this.userUri = userUri; }
Example #11
Source File: GoogleOAuthAuthenticator.java From codenvy with Eclipse Public License 1.0 | 5 votes |
@Inject public GoogleOAuthAuthenticator( @Nullable @Named("oauth.google.clientid") String clientId, @Nullable @Named("oauth.google.clientsecret") String clientSecret, @Nullable @Named("oauth.google.redirecturis") String[] redirectUris, @Nullable @Named("oauth.google.authuri") String authUri, @Nullable @Named("oauth.google.tokenuri") String tokenUri) throws IOException { if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && redirectUris != null && redirectUris.length != 0) { configure( new GoogleAuthorizationCodeFlow.Builder( new NetHttpTransport(), new JacksonFactory(), new GoogleClientSecrets() .setWeb( new GoogleClientSecrets.Details() .setClientId(clientId) .setClientSecret(clientSecret) .setRedirectUris(Arrays.asList(redirectUris)) .setAuthUri(authUri) .setTokenUri(tokenUri)), Arrays.asList( "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile")) .setDataStoreFactory(new MemoryDataStoreFactory()) .setApprovalPrompt("auto") .setAccessType("online") .build(), Arrays.asList(redirectUris)); } }
Example #12
Source File: OAuthAuthenticator.java From che with Eclipse Public License 2.0 | 5 votes |
/** * This method should be invoked by child class for initialization default instance of {@link * AuthorizationCodeFlow} that will be used for authorization */ protected void configure( String clientId, String clientSecret, String[] redirectUris, String authUri, String tokenUri, MemoryDataStoreFactory dataStoreFactory, List<String> scopes) throws IOException { final AuthorizationCodeFlow authorizationFlow = new AuthorizationCodeFlow.Builder( BearerToken.authorizationHeaderAccessMethod(), new NetHttpTransport(), new JacksonFactory(), new GenericUrl(tokenUri), new ClientParametersAuthentication(clientId, clientSecret), clientId, authUri) .setDataStoreFactory(dataStoreFactory) .setScopes(scopes) .build(); LOG.debug( "clientId={}, clientSecret={}, redirectUris={} , authUri={}, tokenUri={}, dataStoreFactory={}", clientId, clientSecret, redirectUris, authUri, tokenUri, dataStoreFactory); configure(authorizationFlow, Arrays.asList(redirectUris)); }
Example #13
Source File: Server.java From rides-java-sdk with MIT License | 5 votes |
/** * Creates an {@link OAuth2Credentials} object that can be used by any of the servlets. * * Throws an {@throws IOException} when no client ID or secret found in secrets.properties */ static OAuth2Credentials createOAuth2Credentials(SessionConfiguration config) throws IOException { return new OAuth2Credentials.Builder() .setCredentialDataStoreFactory(MemoryDataStoreFactory.getDefaultInstance()) .setRedirectUri(config.getRedirectUri()) .setScopes(config.getScopes()) .setClientSecrets(config.getClientId(), config.getClientSecret()) .build(); }
Example #14
Source File: PKCESample.java From google-oauth-java-client with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { DATA_STORE_FACTORY = new MemoryDataStoreFactory(); final Credential credential = authorize(); System.out.println("Successfully obtained credential from Keycloak running on localhost."); final String accessToken = credential.getAccessToken(); System.out.println("Retrieved an access token of length " + accessToken.length()); return; } catch (IOException e) { System.err.println(e.getMessage()); } catch (Throwable t) { t.printStackTrace(); } System.exit(1); }
Example #15
Source File: GoogleAuthorizeUtil.java From tutorials with MIT License | 5 votes |
public static Credential authorize() throws IOException, GeneralSecurityException { InputStream in = GoogleAuthorizeUtil.class.getResourceAsStream("/google-sheets-client-secret.json"); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(), new InputStreamReader(in)); List<String> scopes = Arrays.asList(SheetsScopes.SPREADSHEETS); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), clientSecrets, scopes).setDataStoreFactory(new MemoryDataStoreFactory()) .setAccessType("offline").build(); Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); return credential; }
Example #16
Source File: WSO2OAuthAuthenticator.java From codenvy with Eclipse Public License 1.0 | 5 votes |
@Inject public WSO2OAuthAuthenticator( @Nullable @Named("oauth.wso2.clientid") String clientId, @Nullable @Named("oauth.wso2.clientsecret") String clientSecret, @Nullable @Named("oauth.wso2.redirecturis") String[] redirectUris, @Nullable @Named("oauth.wso2.authuri") String authUri, @Nullable @Named("oauth.wso2.tokenuri") String tokenUri, @Nullable @Named("oauth.wso2.useruri") String userUri) throws IOException { this.userUri = userUri; if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret) && !isNullOrEmpty(authUri) && !isNullOrEmpty(tokenUri) && redirectUris != null && redirectUris.length != 0) { configure( clientId, clientSecret, redirectUris, authUri, tokenUri, new MemoryDataStoreFactory(), singletonList(SCOPE)); } }
Example #17
Source File: MemoryDataStoreFactoryTest.java From google-http-java-client with Apache License 2.0 | 4 votes |
@Override protected DataStoreFactory newDataStoreFactory() { return MemoryDataStoreFactory.getDefaultInstance(); }
Example #18
Source File: NotificationServlet.java From google-api-java-client with Apache License 2.0 | 2 votes |
/** * Constructor to be used for testing and demo purposes that uses * {@link MemoryDataStoreFactory#getDefaultInstance()} which means it will NOT persist the * notification channels when the servlet process dies, so it is a bad choice for a production * application. */ public NotificationServlet() throws IOException { this(MemoryDataStoreFactory.getDefaultInstance()); }