我正在尝试使用 Angular 4 获取访问令牌。当用户使用 Google 登录时,我得到以下数据。
authToken // *
id
email
.
.
.
name
我认为该变量
authToken
不是access token
因为当我尝试使用以下代码(spring boot)验证它时,GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance()) .setAudience(Collections.singletonList( "ID_CLIENT") .build(); try { GoogleIdToken idToken = verifier.verify(accessToken); if (idToken != null) { Payload payload = idToken.getPayload(); String userId = payload.getSubject(); System.out.println("User ID: " + userId); 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"); System.out.println(accessToken); return accessToken; } else { System.out.println("null"); return "**this is not a valid Token**"; } } catch (IllegalArgumentException e) { return "IllegalArgumentException"; }
它返回
IllegalArgumentException
那么我如何使用Angular获取Google 访问令牌