com.github.scribejava.apis.GoogleApi20 Java Examples
The following examples show how to use
com.github.scribejava.apis.GoogleApi20.
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: AccountService.java From runelite with BSD 2-Clause "Simplified" License | 8 votes |
@GetMapping("/login") public OAuthResponse login(@RequestParam UUID uuid) { State state = new State(); state.setUuid(uuid); state.setApiVersion(RuneLiteAPI.getVersion()); OAuth20Service service = new ServiceBuilder() .apiKey(oauthClientId) .apiSecret(oauthClientSecret) .scope(SCOPE) .callback(oauthCallback) .state(gson.toJson(state)) .build(GoogleApi20.instance()); final Map<String, String> additionalParams = new HashMap<>(); additionalParams.put("prompt", "select_account"); String authorizationUrl = service.getAuthorizationUrl(additionalParams); OAuthResponse lr = new OAuthResponse(); lr.setOauthUrl(authorizationUrl); lr.setUid(uuid); return lr; }
Example #2
Source File: Oauth20Service.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
private DefaultApi20 instance(Provider provider) { switch (provider) { case GITHUB: return GitHubApi.instance(); case GOOGLE: return GoogleApi20.instance(); case FACEBOOK: return FacebookApi.instance(); case WEIBO: return SinaWeiboApi20.instance(); default: throw new RuntimeException(String.format("provider %s undefined", provider.name())); } }
Example #3
Source File: OAuthManagerProviders.java From react-native-oauth with MIT License | 5 votes |
private static OAuth20Service googleService( final HashMap cfg, @Nullable final ReadableMap opts, final String callbackUrl) { ServiceBuilder builder = OAuthManagerProviders._oauth2ServiceBuilder(cfg, opts, callbackUrl); return builder.build(GoogleApi20.instance()); }
Example #4
Source File: GoogleService.java From tutorials with MIT License | 5 votes |
@PostConstruct private void init(){ this.service = new ServiceBuilder(API_KEY) .apiSecret(API_SECRET) .scope(SCOPE) .callback(CALLBACK) .build(GoogleApi20.instance()); }
Example #5
Source File: AccountService.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@GetMapping("/callback") public Object callback( HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false) String error, @RequestParam String code, @RequestParam("state") String stateStr ) throws InterruptedException, ExecutionException, IOException { if (error != null) { logger.info("Error in oauth callback: {}", error); return null; } State state = gson.fromJson(stateStr, State.class); logger.info("Got authorization code {} for uuid {}", code, state.getUuid()); OAuth20Service service = new ServiceBuilder() .apiKey(oauthClientId) .apiSecret(oauthClientSecret) .scope(SCOPE) .callback(oauthCallback) .state(gson.toJson(state)) .build(GoogleApi20.instance()); OAuth2AccessToken accessToken = service.getAccessToken(code); // Access user info OAuthRequest orequest = new OAuthRequest(Verb.GET, USERINFO); service.signRequest(accessToken, orequest); Response oresponse = service.execute(orequest); if (oresponse.getCode() / 100 != 2) { // Could be a forged result return null; } UserInfo userInfo = gson.fromJson(oresponse.getBody(), UserInfo.class); logger.info("Got user info: {}", userInfo); try (Connection con = sql2o.open()) { con.createQuery("insert ignore into users (username) values (:username)") .addParameter("username", userInfo.getEmail()) .executeUpdate(); UserEntry user = con.createQuery("select id from users where username = :username") .addParameter("username", userInfo.getEmail()) .executeAndFetchFirst(UserEntry.class); if (user == null) { logger.warn("Unable to find newly created user session"); return null; // that's weird } // insert session con.createQuery("insert ignore into sessions (user, uuid) values (:user, :uuid)") .addParameter("user", user.getId()) .addParameter("uuid", state.getUuid().toString()) .executeUpdate(); logger.info("Created session for user {}", userInfo.getEmail()); } response.sendRedirect(RL_REDIR); notifySession(state.getUuid(), userInfo.getEmail()); return ""; }