• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GoogleApi20类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.github.scribejava.apis.GoogleApi20的典型用法代码示例。如果您正苦于以下问题:Java GoogleApi20类的具体用法?Java GoogleApi20怎么用?Java GoogleApi20使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GoogleApi20类属于com.github.scribejava.apis包,在下文中一共展示了GoogleApi20类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: googleExample

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
public void googleExample () {
    // Replace these with your client id and secret
    final String clientId = mySecrets.getString("googleId");
    final String clientSecret = mySecrets.getString("googleSecret");
    service = new ServiceBuilder()
            .apiKey(clientId)
            .apiSecret(clientSecret)
            .callback(CALLBACK_URL)
            // .scope("https://www.googleapis.com/auth/plus.login ")
            .scope("https://www.googleapis.com/auth/plus.circles.write https://www.googleapis.com/auth/plus.circles.read https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.stream.read")

            .build(GoogleApi20.instance());

    System.out.println();

    // Obtain the Authorization URL
    System.out.println("Fetching the Authorization URL...");
    final String authorizationUrl = service.getAuthorizationUrl();
    myPage.getEngine().load(authorizationUrl);
}
 
开发者ID:tomrom95,项目名称:GameAuthoringEnvironment,代码行数:21,代码来源:BrowserView.java


示例2: Auth

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
public Auth(String clientId, String clientSecret, String callbackURL) throws NoSuchAlgorithmException {
    this.clientId = clientId;
    this.clientSecret = clientSecret;
    this.gson = new Gson();
    this.authUsers = new ArrayList<>();
    // TODO: this is where authorized users are hardcoded
    // The email address must be one managed by Google
    //authUsers.add("[email protected]");
    this.globalService = new ServiceBuilder()
            .apiKey(clientId)
            .apiSecret(clientSecret)
            .scope("email") // replace with desired scope
            .callback(callbackURL)
            .build(GoogleApi20.instance());

    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
    keyPairGenerator.initialize(2048);
    this.keyPair = keyPairGenerator.genKeyPair();
    this.callbackURL = callbackURL;
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:21,代码来源:Auth.java


示例3: getAuthURL

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
/**
 * @return A string containing a URL that we can send visitors to in order to authenticate them
 */
public String getAuthURL(String originatingURL){
    // I think we have to create a new service for every request we send out
    // since each one needs a different secretState
    final OAuth20Service service = new ServiceBuilder()
            .apiKey(clientId)
            .apiSecret(clientSecret)
            .scope("email") // replace with desired scope
            .state(generateSharedGoogleSecret(originatingURL))
            .callback(callbackURL)
            .build(GoogleApi20.instance());

    final Map<String, String> additionalParams = new HashMap<>();
    additionalParams.put("access_type", "offline");
    additionalParams.put("prompt", "consent");
    final String authorizationUrl = service.getAuthorizationUrl(additionalParams);

    return authorizationUrl;
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:22,代码来源:Auth.java


示例4: login

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
@RequestMapping("/login")
public OAuthResponse login()
{
	UUID uuid = UUID.randomUUID();

	State state = new State();
	state.setUuid(uuid);
	state.setApiVersion(RuneLiteAPI.getVersion());

	OAuth20Service service = new ServiceBuilder()
		.apiKey(oauthClientId)
		.apiSecret(oauthClientSecret)
		.scope(SCOPE)
		.callback(RL_OAUTH_URL)
		.state(gson.toJson(state))
		.build(GoogleApi20.instance());

	String authorizationUrl = service.getAuthorizationUrl();

	OAuthResponse lr = new OAuthResponse();
	lr.setOauthUrl(authorizationUrl);
	lr.setUid(uuid);

	return lr;
}
 
开发者ID:runelite,项目名称:runelite,代码行数:26,代码来源:AccountService.java


示例5: googleLogin

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
public void googleLogin() throws IOException {
    String CALL_BACK_URL="http://localhost:8084/loginAndSec/GcallBack";
    ExternalContext externalContext = externalContext();
    HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
   
    String callBackURL = CALL_BACK_URL; 
    //System.out.println("google.GoogleLoginServlet.doGet(): callBackURL=" + callBackURL);
    //Configure
    ServiceBuilder builder = new ServiceBuilder();
    OAuth20Service service = builder.apiKey(CLIENT_ID)
            .apiSecret(CLIENT_SECRET)
            .callback(callBackURL)
            .scope("email")
            .build(GoogleApi20.instance()); //Now build the call

    HttpSession sess = request.getSession();
    sess.setAttribute("oauth2Service", service);
    String authURL = service.getAuthorizationUrl(null);
    //System.out.println("service.getAuthorizationUrl(null)->" + authURL);
    externalContext.redirect(authURL);
}
 
开发者ID:ljug,项目名称:java-tutorials,代码行数:22,代码来源:LoginManager.java


示例6: main

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
public static void main(String[] args) {
	ServiceBuilder builder = new ServiceBuilder();
	UUID state = UUID.randomUUID();
	OAuth20Service service = builder.state(state.toString()).scope("https://www.googleapis.com/auth/gmail.send").apiKey("654832567742-6udg14sfuif69g84c78ss3s3msdlf33l.apps.googleusercontent.com").apiSecret("SDFwrgfsdSeQnFtSDFSDFzHd").callback("https://tburne.net/oauth/index.html").build(GoogleApi20.instance());
	Hashtable<String, String> params = new Hashtable<String, String>();
	params.put("access_type", "offline");
	params.put("approval_prompt", "force");
	System.out.println("Redirect Resource Owner to " + service.getAuthorizationUrl(params) + " with state " + state.toString());	
}
 
开发者ID:tburne,项目名称:blog-examples,代码行数:10,代码来源:ClientRequestAuthorizationCode.java


示例7: createOAuthService

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
public OAuth20Service createOAuthService(HttpServletRequest req, String csrfToken) {
    ServiceBuilder builder = new ServiceBuilder();
    ServiceBuilder serviceBuilder = builder
            .apiKey(configuration.getClientId())
            .apiSecret(configuration.getClientSecret())
            .callback(assembleCallbackUrl(req) + "/oauth2callback")
            .scope("openid profile email " + configuration.getOAuth2Scopes())
            .debug();
    if (csrfToken != null && !csrfToken.isEmpty()) {
        serviceBuilder.state(csrfToken);
    }

    return serviceBuilder.build(GoogleApi20.instance());

}
 
开发者ID:atbashEE,项目名称:jsr375-extensions,代码行数:16,代码来源:OAuth2ServiceFactory.java


示例8: init

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
@Override
public void init(InitContext context) {
  String state = context.generateCsrfState();
  OAuth20Service scribe = prepareScribe(context)
    .scope("email profile")
    .state(state)
    .build(GoogleApi20.instance());
  String url = scribe.getAuthorizationUrl();
  context.redirectTo(url);
}
 
开发者ID:steven-turner,项目名称:sonar-auth-google,代码行数:11,代码来源:GoogleIdentityProvider.java


示例9: callback

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
@Override
public void callback(CallbackContext context) {
  context.verifyCsrfState();

  HttpServletRequest request = context.getRequest();
  OAuth20Service scribe = prepareScribe(context).build(GoogleApi20.instance());
  String oAuthVerifier = request.getParameter("code");
  OAuth2AccessToken accessToken = scribe.getAccessToken(new Verifier(oAuthVerifier));

  OAuthRequest userRequest = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v2/userinfo", scribe);
  scribe.signRequest(accessToken, userRequest);

  com.github.scribejava.core.model.Response userResponse = userRequest.send();
  if (!userResponse.isSuccessful()) {
    throw new IllegalStateException(format("Fail to authenticate the user. Error code is %s, Body of the response is %s",
      userResponse.getCode(), userResponse.getBody()));
  }
  String userResponseBody = userResponse.getBody();
  LOGGER.trace("User response received : %s", userResponseBody);
  GsonUser gsonUser = GsonUser.parse(userResponseBody);

  UserIdentity userIdentity = UserIdentity.builder()
    .setProviderLogin(gsonUser.getEmail())
    .setLogin(gsonUser.getEmail())
    .setName(gsonUser.getName())
    .setEmail(gsonUser.getEmail())
    .build();
  context.authenticate(userIdentity);
  context.redirectToRequestedPage();
}
 
开发者ID:steven-turner,项目名称:sonar-auth-google,代码行数:31,代码来源:GoogleIdentityProvider.java


示例10: googleService

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
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());
}
 
开发者ID:fullstackreact,项目名称:react-native-oauth,代码行数:9,代码来源:OAuthManagerProviders.java


示例11: createOAuthService

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
/**
 * Creates an OAuthService for authentication a user with OAuth
 *
 * @param oAuthProvider The OAuth provider Enum
 * @return An Optional OAuthService
 */
public Optional<OAuthService> createOAuthService(OAuthProvider oAuthProvider) {
    Objects.requireNonNull(oAuthProvider, Required.OAUTH_PROVIDER.toString());

    Config config = Application.getInstance(Config.class);
    OAuthService oAuthService = null;
    switch (oAuthProvider) {
    case TWITTER:
        oAuthService = new ServiceBuilder(config.getString(Key.OAUTH_TWITTER_KEY))
        .callback(config.getString(Key.OAUTH_TWITTER_CALLBACK))
        .apiSecret(config.getString(Key.OAUTH_TWITTER_SECRET))
        .build(TwitterApi.instance());
        break;
    case GOOGLE:
        oAuthService = new ServiceBuilder(config.getString(Key.OAUTH_GOOGLE_KEY))
        .scope(SCOPE)
        .callback(config.getString(Key.OAUTH_GOOGLE_CALLBACK))
        .apiSecret(config.getString(Key.OAUTH_GOOGLE_SECRET))
        .state("secret" + new SecureRandom().nextInt(MAX_RANDOM))
        .build(GoogleApi20.instance());
        break;
    case FACEBOOK:
        oAuthService = new ServiceBuilder(config.getString(Key.OAUTH_FACEBOOK_KEY))
        .callback(config.getString(Key.OAUTH_FACEBOOK_CALLBACK))
        .apiSecret(config.getString(Key.OAUTH_FACEBOOK_SECRET))
        .build(FacebookApi.instance());
        break;
    default:
        break;
    }

    return (oAuthService == null) ? Optional.empty() : Optional.of(oAuthService);
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:39,代码来源:RequestHelper.java


示例12: main

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
public static void main (String ... args) {
    // Replace these with your client id and secret
    mySecrets = ResourceBundle.getBundle("facebookutil/secret");
    final String clientId = mySecrets.getString("googleId");
    final String clientSecret = mySecrets.getString("googleSecret");
    final OAuth20Service service = new ServiceBuilder()
            .apiKey(clientId)
            .apiSecret(clientSecret)
            .scope("https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.circles.write https://www.googleapis.com/auth/plus.circles.read https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.stream.read")
            .callback("https://github.com/duke-compsci308-spring2016/voogasalad_GitDepends")
            .build(GoogleApi20.instance());
    Scanner in = new Scanner(System.in, "UTF-8");

    System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
    System.out.println();

    // Obtain the Authorization URL
    System.out.println("Fetching the Authorization URL...");

    final Map<String, String> additionalParams = new HashMap<>();
    additionalParams.put("access_type", "offline");
    // force to retrieve refresh token (if users are asked not the first time)
    additionalParams.put("prompt", "consent");
    final String authorizationUrl = service.getAuthorizationUrl(additionalParams);
    System.out.println("Got the Authorization URL!");
    System.out.println("Now go and authorize ScribeJava here:");
    System.out.println(authorizationUrl);
    System.out.println("And paste the authorization code here");
    System.out.print(">>");
    final String code = in.nextLine();
    System.out.println();

    System.out.println("Trading the Request Token for an Access Token...");
    OAuth2AccessToken accessToken = service.getAccessToken(code);
    System.out.println("Got the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken +
                       ", 'rawResponse'='" + accessToken.getRawResponse() + "')");

    System.out.println("Refreshing the Access Token...");
    accessToken = service.refreshAccessToken(accessToken.getRefreshToken());
    System.out.println("Refreshed the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken +
                       ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
    System.out.println();

    // Now let's go and ask for a protected resource!
    System.out.println("Now we're going to access a protected resource...");
    while (true) {
        System.out
                .println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)");
        System.out.print(">>");
        final String query = in.nextLine();
        System.out.println();

        final String requestUrl;
        if ("exit".equals(query)) {
            break;
        }
        else if (query == null || query.isEmpty()) {
            requestUrl = PROTECTED_RESOURCE_URL;
        }
        else {
            requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query;
        }

        final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl, service);
        service.signRequest(accessToken, request);
        final Response response = request.send();
        System.out.println();
        System.out.println(response.getCode());
        System.out.println(response.getBody());

        System.out.println();
    }
    in.close();
}
 
开发者ID:tomrom95,项目名称:GameAuthoringEnvironment,代码行数:77,代码来源:GooglePlusExample.java


示例13: getApi

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
@Override
protected BaseApi<OAuth20Service> getApi() {
    return GoogleApi20.instance();
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:5,代码来源:Google2Client.java


示例14: callback

import com.github.scribejava.apis.GoogleApi20; //导入依赖的package包/类
@RequestMapping("/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(RL_OAUTH_URL)
		.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 "";
}
 
开发者ID:runelite,项目名称:runelite,代码行数:77,代码来源:AccountService.java



注:本文中的com.github.scribejava.apis.GoogleApi20类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IntSumReducer类代码示例发布时间:2022-05-22
下一篇:
Java TextInfo类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap