상황을 충돌합니다. 지금까지 (훨씬 더 간단한) openId APi를 사용하여 사용자를 인증했지만 지금은 제거 될 것으로 보이며 oAuth2는 "새로운"것입니다.OAuth2를 OAuthServiceFactory.getOAuthService() getCurrentUser는()
질문 :
나는이 내 사용자를 인증하는 apacha oltu를 사용하는 다음 코드를
@GET
public Response step1()
throws ServletException, IOException, URISyntaxException, OAuthSystemException {
OAuthClientRequest request = OAuthClientRequest
.authorizationProvider(OAuthProviderType.GOOGLE)
.setClientId(CLIENT_ID)
.setScope("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email")
.setRedirectURI(REDIRECT_URI)
.setResponseType("code")
.buildQueryMessage();
logger.info("start oauth process: " + request.getLocationUri());
//We send a redirect request to the browser so it can go to the consent screen of google.
return Response.status(Response.Status.TEMPORARY_REDIRECT).location(new URI(request.getLocationUri())).build();
}
@GET
@Path("loggedin")
public Response getCode(@QueryParam("code") String code)
throws ServletException, IOException, URISyntaxException, OAuthSystemException, OAuthProblemException, OAuthRequestException {
logger.info("response from redirect. We obtained the following code: " + code);
OAuthClientRequest request = OAuthClientRequest
.tokenProvider(OAuthProviderType.GOOGLE)
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setCode(code)
.setScope("https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email")
.setRedirectURI(REDIRECT_URI)
.buildBodyMessage();
OAuthClient client = new OAuthClient(new URLConnectionClient());
OAuthJSONAccessTokenResponse tokenResponse = client.accessToken(request, OAuthJSONAccessTokenResponse.class);
logger.log(Level.WARNING, "token: " + tokenResponse.getAccessToken() + " valid to: " + tokenResponse.getExpiresIn());
return Response.status(Response.Status.TEMPORARY_REDIRECT).location(new URI("../index.html")).build();
}
문제는 지금 그 InvalidOAuthParametersException와 OAuthServiceFactory.getOAuthService().getCurrentUser()
충돌합니다. 나를 위해 작동하지 않았다/
이전에는 UserService를 사용하여 기본 사용자 객체에 액세스했습니다. 그러나 이것은 openId에서만 작동하는 것으로 보입니다.
내 oltu 접근 방식에 대한 대안은 구글 + 물건에 서명을 사용하는 것입니다. 이유는 내가이 간다 하나의 예를 발견 하고이 자바 스크립트 물건을 사용 - 엄격하게 서버에 모든 oauth 물건을 처리하고 다른 js 라이브러리를 포함하지 않습니다.
"ID"와 "사용자가 로그인"에 대한 사용자 개체의 어떤 종류에 액세스 할 수있는 대안은 있습니까? (UserService.getCurrentUser()에서는 사용자가 로그인하지 않은 경우 null이 반환됩니다).