Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 2.07 KB

README.md

File metadata and controls

57 lines (42 loc) · 2.07 KB

OAuth2 java client

A client library which uses oauth client secrets to send authorized requests or generate access tokens

OAuth2 client for console apps

Send authorized request, with access token generated by Google OAuth server, using google http client library
OАuthClientConfig config = OАuthClientConfig
       .setClient("::client::")
       .setSecret("::secret::")
       .setScopes(setOf("scope1", "scope2"))
       //you can pass other implementation of CredentialsStore, like - CredentialsDatabase
       .setCredentialsStorage(LocalCredentialsFileStorage(filePath))
       .build()
             
HttpRequestFactory factory = NetHttpTransport().createRequestFactory(
         BearerTokenInterceptor.newGoogleInterceptor(config))
 
 // do HTTP call

NOTE: your client should have redirect url : 'http://localhost:8089/oauth2callback'

NOTE: if this code is invoked by gradle task(groovy) you task should contain this line: 'standardInput = System.in' or Scanner object will throw exception.

Generate credentials using Google OAuth server for offline apps
OАuthClientConfig config = OАuthClientConfig
       .setClient("::client::")
       .setSecret("::secret::")
       .setScopes(setOf("scope1", "scope2"))
       .setCredentialsStorage(LocalCredentialsFileStorage(filePath))
       .build()
       
GoogleOAuthCredentialsFactory factory = new GoogleOAuthCredentialsFactory(config);
Credentials credentials = factory.getCredentials();

// do some action with credentials

License

Copyright 2017 clouWay ood.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.