本文整理汇总了Java中com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier类的典型用法代码示例。如果您正苦于以下问题:Java GoogleIdTokenVerifier类的具体用法?Java GoogleIdTokenVerifier怎么用?Java GoogleIdTokenVerifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GoogleIdTokenVerifier类属于com.google.api.client.googleapis.auth.oauth2包,在下文中一共展示了GoogleIdTokenVerifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AuthChecker
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
public AuthChecker(String[] clientIDs, String audience) {
this.mClientIDs = Arrays.asList(clientIDs);
this.mAudience = audience;
HttpTransport transport = new NetHttpTransport();
this.mJFactory = new JacksonFactory();
this.mVerifier = new GoogleIdTokenVerifier.Builder(transport, mJFactory)
.build();
}
示例2: GoogleAuthenticator
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
public GoogleAuthenticator(
final String clientId,
final UserRepository userRepo,
@Nullable final String hostedDomain
) {
this.userRepo = userRepo;
tokenVerifier = new GoogleIdTokenVerifier.Builder(
new NetHttpTransport(), JacksonFactory.getDefaultInstance())
.setAudience(Collections.singleton(clientId))
.setIssuer(ISSUER)
.build();
this.hostedDomain = hostedDomain;
}
示例3: tokenSignIn
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的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);
}
}
}
示例4: Checker
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
public Checker(String[] clientIDs, String audience) {
mClientIDs = Arrays.asList(clientIDs);
mAudience = audience;
NetHttpTransport transport = new NetHttpTransport();
mJFactory = new GsonFactory();
mVerifier = new GoogleIdTokenVerifier(transport, mJFactory);
}
示例5: Checker
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
public Checker(String[] clientIDs, String audience) {
mClientIDs = Arrays.asList(clientIDs);
mAudience = audience;
NetHttpTransport transport = new NetHttpTransport();
mJFactory = new GsonFactory();
mVerifier = new GoogleIdTokenVerifier(transport, mJFactory);
}
示例6: getUserByIdToken
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的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.");
}
示例7: getUserUUIDByIdToken
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的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.");
}
示例8: verify
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
private GoogleIdToken verify(String idTokenString) throws GeneralSecurityException, IOException
{
List<String> audience = Collections.singletonList(authenticationSettings.getGoogleAppClientId());
GoogleIdTokenVerifier googleIdTokenVerifier = new GoogleIdTokenVerifier.Builder(
googlePublicKeysManager).setAudience(audience).build();
return googleIdTokenVerifier.verify(idTokenString);
}
示例9: GoogleChecker
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
public GoogleChecker(String[] clientIDs, String audience) {
mClientIDs = Arrays.asList(clientIDs);
mAudience = audience;
NetHttpTransport transport = new NetHttpTransport();
mJFactory = new GsonFactory();
mVerifier = new GoogleIdTokenVerifier(transport, mJFactory);
}
示例10: parseGoogleAccountFromIdToken
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的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);
}
示例11: GoogleJwtAuthenticator
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
public GoogleJwtAuthenticator() {
this(new GoogleIdTokenVerifier.Builder(Client.getInstance().getHttpTransport(),
Client.getInstance().getJsonFactory()).build());
}
示例12: EndpointsPeerAuthenticator
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
public EndpointsPeerAuthenticator() {
Client client = Client.getInstance();
GooglePublicKeysManager keyManager = new GooglePublicKeysManager.Builder(
client.getHttpTransport(), client.getJsonFactory()).setPublicCertsEncodedUrl(
PUBLIC_CERT_URL).build();
GoogleIdTokenVerifier verifier =
new GoogleIdTokenVerifier.Builder(keyManager).setIssuer(ISSUER).build();
jwtAuthenticator = new GoogleJwtAuthenticator(verifier);
}
示例13: processRegistration
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的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";
}
示例14: googleIdTokenVerifier
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
@Provides
@Singleton
public GoogleIdTokenVerifier googleIdTokenVerifier(JsonFactory jsonFactory) {
return new GoogleIdTokenVerifier(new NetHttpTransport(), jsonFactory);
}
示例15: googleSignInVerifier
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; //导入依赖的package包/类
@Provides
@Singleton
public GoogleSignInVerifier googleSignInVerifier(GoogleIdTokenVerifier googleIdTokenVerifier, JsonFactory jsonFactory) {
return new GoogleSignInVerifier(googleClientId, googleIdTokenVerifier, jsonFactory);
}