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

Java Payload类代码示例

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

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



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

示例1: idTokenPayloadToGoogleAccount

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
private static GoogleAccount idTokenPayloadToGoogleAccount(Payload payload) {
	String id = payload.getSubject();
	if (Preconditions.isEmptyString(id)) {
		LOGGER.error("No subject ID found in ID token payload, please check your scope settings.");
		return null;
	}

	String email = payload.getEmail();
	if (Preconditions.isEmptyString(email)) {
		LOGGER.error("No email found in ID token payload, please check your scope settings.");
		return null;
	}
	//		boolean emailVerified = Boolean.valueOf(payload.getEmailVerified());
	//		LOGGER.debug(String.format("email: %s (verified: %s)", email, emailVerified));
	String name = (String) payload.get("name");
	if (Preconditions.isEmptyString(name)) {
		name = "John/Jane Doe";
	}
	//		LOGGER.debug(String.format("name: %s", name));
	String pictureUrl = (String) payload.get("picture");
	if (Preconditions.isEmptyString(pictureUrl)) {
		pictureUrl = "https://ssl.gstatic.com/accounts/ui/avatar_1x.png";
	}
	//		LOGGER.debug(String.format("pictureUrl: %s", pictureUrl));
	//		String locale = (String) payload.get("locale");
	//		LOGGER.debug(String.format("locale: %s", locale));
	//		String familyName = (String) payload.get("family_name");
	//		String givenName = (String) payload.get("given_name");
	//		LOGGER.debug(String.format("Full Name: %s,%s", familyName, givenName));

	return new GoogleAccount(id, email, name, pictureUrl);
}
 
开发者ID:sgr-io,项目名称:social-signin,代码行数:33,代码来源:GoogleSignInService.java


示例2: setUp

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  payload = new Payload();
  payload.setAuthorizedParty(CLIENT_ID);
  payload.setAudience(AUDIENCE);
  payload.setEmail(EMAIL);
  payload.setSubject(USER_ID);
  authenticator = new GoogleJwtAuthenticator(verifier);
  request = new MockHttpServletRequest();
  attr = Attribute.from(request);
  attr.set(Attribute.API_METHOD_CONFIG, config);
  attr.set(Attribute.ENABLE_CLIENT_ID_WHITELIST, true);
  request.addHeader(GoogleAuth.AUTHORIZATION_HEADER, "Bearer " + TOKEN);
  when(token.getPayload()).thenReturn(payload);
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:16,代码来源:GoogleJwtAuthenticatorTest.java


示例3: tokenSignIn

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
@RequestMapping(value = "/tokensignin", method = RequestMethod.POST)
public void tokenSignIn(@RequestParam("token") String token, HttpServletResponse response)
        throws GeneralSecurityException, IOException {

    final NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    final JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    GoogleIdTokenVerifier verifier =
            new GoogleIdTokenVerifier.Builder(transport, jsonFactory)
                    .setAudience(Collections.singletonList(oauthClientId))
                    .build();

    final GoogleIdToken googleIdToken = verifier.verify(token);

    if (googleIdToken == null) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }
    final Payload payload = googleIdToken.getPayload();
    final Boolean emailVerified = payload.getEmailVerified();

    if (emailVerified) {
        final String login = userDetailDao.getUserLoginByEmail(payload.getEmail());
        if (StringUtils.isNotEmpty(login)) {
            final UserAuthView userDetails = userDetailDao.getUserAuthView(login);

            final Authentication auth =
                    new UsernamePasswordAuthenticationToken(userDetails,
                                                            null,
                                                            userDetails.getAuthorities());
            SecurityContextHolder.getContext().setAuthentication(auth);
            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            response.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
    }
}
 
开发者ID:kTT,项目名称:adjule,代码行数:37,代码来源:UserAuthEndpoint.java


示例4: getGoogleId

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
private static String getGoogleId(String gToken) {

		if (gToken != null) {
			Checker checker = new Checker(web_clientId, audience);
			Payload payload = checker.check(gToken);

			if (payload != null) {
				return payload.getUserId();
			}
		}
		return null;
	}
 
开发者ID:dasa123,项目名称:GisWeb,代码行数:13,代码来源:Application.java


示例5: getGoogleMail

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
private static String getGoogleMail(String gToken) {

		if (gToken != null) {
			Checker checker = new Checker(web_clientId, audience);
			Payload payload = checker.check(gToken);

			if (payload != null) {
				return payload.getEmail();
			}
		}
		return null;
	}
 
开发者ID:dasa123,项目名称:GisWeb,代码行数:13,代码来源:Application.java


示例6: getUserByIdToken

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
public User getUserByIdToken(String idTokenString) throws GeneralSecurityException, IOException, IllegalArgumentException, ObjectNotFoundException, NdexException {
	
	ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder();
	
	GoogleIdTokenVerifier localVerifier = new GoogleIdTokenVerifier.Builder(builder.build(), new JacksonFactory())
		    .setAudience(Collections.singletonList(clientID))
		    // Or, if multiple clients access the backend:
		    //.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
		    .build();
	
	GoogleIdToken idToken = localVerifier.verify(idTokenString);
	if (idToken != null) {
	  Payload payload = idToken.getPayload();

	  // Print user identifier
	//  String userId = payload.getSubject();
	//  System.out.println("User ID: " + userId);

	  // Get profile information from payload
	  String email = payload.getEmail();
/*	  boolean emailVerified = Boolean.valueOf(payload.getEmailVerified());
	  String name = (String) payload.get("name");
	  String pictureUrl = (String) payload.get("picture");
	  String locale = (String) payload.get("locale");
	  String familyName = (String) payload.get("family_name");
	  String givenName = (String) payload.get("given_name"); */

		 try (UserDAO userDao = new UserDAO()) {
			 User user = userDao.getUserByEmail(email.toLowerCase(),true);
			 return user;	
		 }	catch ( SQLException e1) {
			 e1.printStackTrace();
			  throw new UnauthorizedOperationException("SQL Error when getting user by email: " + e1.getMessage());
		 }
	} 
	  throw new UnauthorizedOperationException("Invalid OAuth ID token.");
	
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:39,代码来源:GoogleOpenIDAuthenticator.java


示例7: getUserUUIDByIdToken

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
public UUID getUserUUIDByIdToken(String idTokenString) throws GeneralSecurityException, IOException, IllegalArgumentException, ObjectNotFoundException, NdexException {
	
	ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder();
	
	GoogleIdTokenVerifier localVerifier = new GoogleIdTokenVerifier.Builder(builder.build(), new JacksonFactory())
		    .setAudience(Collections.singletonList(clientID))
		    // Or, if multiple clients access the backend:
		    //.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
		    .build();
	
	GoogleIdToken idToken = localVerifier.verify(idTokenString);
	if (idToken != null) {
	  Payload payload = idToken.getPayload();

	  // Print user identifier
	  String userId = payload.getSubject();
	  System.out.println("User ID: " + userId);

	  // Get profile information from payload
	  String email = payload.getEmail();

		 try (UserDAO userDao = new UserDAO()) {
			 UUID userUUID = userDao.getUUIDByEmail(email.toLowerCase());
			 return userUUID;	
		 }	catch ( SQLException e1) {
			 e1.printStackTrace();
			  throw new UnauthorizedOperationException("SQL Error when getting user by email: " + e1.getMessage());
		 }
	}
	 
	throw new UnauthorizedOperationException("Invalid OAuth ID token.");
	
	
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:35,代码来源:GoogleOpenIDAuthenticator.java


示例8: parseGoogleAccountFromIdToken

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
private static GoogleAccount parseGoogleAccountFromIdToken(String clientId, String idTokenString) {
	Preconditions.notEmptyString(clientId, "OAuth client ID should be provided.");
	Preconditions.notEmptyString(idTokenString, "IdToken should be provided.");

	GoogleIdTokenVerifier oldVerifier = new GoogleIdTokenVerifier.Builder(getDefaultHttpTransport(), getDefaultJsonFactory())
			.setAudience(Collections.singletonList(clientId))
			// For Android Play Services older than 8.3 and web client
			.setIssuer("accounts.google.com")
			.build();

	GoogleIdTokenVerifier newVerifier = new GoogleIdTokenVerifier.Builder(getDefaultHttpTransport(), getDefaultJsonFactory())
			.setAudience(Collections.singletonList(clientId))
			// For Android Play Services newer than 8.3
			.setIssuer("https://accounts.google.com")
			.build();

	GoogleIdToken idToken;
	try {
		idToken = oldVerifier.verify(idTokenString);
		if (idToken == null) {
			idToken = newVerifier.verify(idTokenString);
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
		return null;
	}
	if (idToken == null) {
		LOGGER.warn(String.format("Invalid or expired Google ID token: %s", idTokenString));
		return null;
	}

	Payload payload = idToken.getPayload();
	for (Entry<String, Object> entry : payload.entrySet()) {
		LOGGER.trace(String.format("%s=%s", entry.getKey(), entry.getValue()));
	}

	return idTokenPayloadToGoogleAccount(payload);
}
 
开发者ID:sgr-io,项目名称:social-signin,代码行数:39,代码来源:GoogleSignInService.java


示例9: processRegistration

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
@Deprecated
@CrossOrigin(origins="*", maxAge=3600)
   @RequestMapping(value="/tokensigningoogle_deprecated", method = RequestMethod.POST, headers = "content-type=application/x-www-form-urlencoded")
   public String processRegistration(@RequestParam("idtoken") String idTokenString) //, ModelMap model)
           throws GeneralSecurityException, IOException {
	logger.info("Doing tokensigningoogle");
       GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(new NetHttpTransport(), new GsonFactory())
               .setAudience(Arrays.asList(environment.getRequiredProperty("google.client_id"))).setIssuer("accounts.google.com").build();

       GoogleIdToken idToken = verifier.verify(idTokenString);
       if (idToken != null) {
           Payload payload = idToken.getPayload();
           // Print user identifier
           String userId = payload.getSubject();
           // Get profile information from payload
           String email = payload.getEmail();
           logger.info("Logged in " + userId + " " + email);
           boolean emailVerified = Boolean.valueOf(payload.getEmailVerified());
           //List<User> users = DbFunction.listHqlNew("FROM User WHERE email = :email", "email", email);

           if (!emailVerified ) { //|| users.isEmpty()) {
               return "/error.html";
           } else {
               //List<String> roles = DbFunction.listSQLNew(
               //        "SELECT role.name FROM user_role_association JOIN role ON role.id = role_id JOIN user on user.id = user_id WHERE user.email = :email",
               //        "email", email);

               List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
               //for (String role : roles) {
               //    authorities.add(new SimpleGrantedAuthority(role));
               //}
               authorities.add(new SimpleGrantedAuthority("USER_AUTH0RITY"));

               UserDetails userDetails = new org.springframework.security.core.userdetails.User(userId,
                               "xxy", true, true, true, true, authorities);
               Authentication authentication = new UsernamePasswordAuthenticationToken(userId, null,
                       userDetails.getAuthorities());
               //UserDetails userDetails = new org.springframework.security.core.userdetails.User(users.get(0).getName(),
               //        "xx", users.get(0).isEnabled(), true, true, true, authorities);
               //Authentication authentication = new UsernamePasswordAuthenticationToken(users.get(0).getName(), null,
               //        userDetails.getAuthorities());
               SecurityContextHolder.clearContext();
               SecurityContextHolder.getContext().setAuthentication(authentication);
               httpSession.setAttribute("sch", userDetails);
       	    logger.info("first check " + httpSession.getAttribute("sch"));

               return "/browsing/databases";
           }
       } else {
           System.out.println("Invalid ID token.");
       }
       return "/error.html";
   }
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:54,代码来源:BrowsingRestController.java


示例10: createAuthentication

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; //导入依赖的package包/类
private Authentication createAuthentication(Payload payload)
{
	String email = payload.getEmail();
	if (email == null)
	{
		throw new AuthenticationServiceException(
				"Google URI token is missing required [email] claim, did you forget to specify scope [email]?");
	}
	Boolean emailVerified = payload.getEmailVerified();
	if (emailVerified != null && !emailVerified)
	{
		throw new AuthenticationServiceException("Google account email is not verified");
	}
	String principal = payload.getSubject();
	String credentials = payload.getAccessTokenHash();

	return runAsSystem(() ->
	{
		User user;

		user = dataService.query(USER, User.class).eq(GOOGLEACCOUNTID, principal).findOne();
		if (user == null)
		{
			// no user with google account
			user = dataService.query(USER, User.class).eq(EMAIL, email).findOne();
			if (user != null)
			{
				// connect google account to user
				user.setGoogleAccountId(principal);
				dataService.update(USER, user);
			}
			else
			{
				// create new user
				String username = email;
				String givenName = payload.containsKey(PROFILE_KEY_GIVEN_NAME) ? payload.get(PROFILE_KEY_GIVEN_NAME)
																						.toString() : null;
				String familyName = payload.containsKey(PROFILE_KEY_FAMILY_NAME) ? payload.get(
						PROFILE_KEY_FAMILY_NAME).toString() : null;
				user = createMolgenisUser(username, email, givenName, familyName, principal);
			}
		}
		if (!user.isActive())
		{
			throw new DisabledException(MolgenisLoginController.ERROR_MESSAGE_DISABLED);
		}
		// create authentication
		Collection<? extends GrantedAuthority> authorities = userDetailsService.getAuthorities(user);
		return new UsernamePasswordAuthenticationToken(user.getUsername(), credentials, authorities);
	});
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:52,代码来源:GoogleAuthenticationProcessingFilter.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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