구매를하기 전에 할 일은 클라이언트의 사용자 ID를 안전하게 서버에 전달하고 사용자 ID와 비교하여 사용자를 확인하는 것입니다. 저장된 자격 증명. 이는 공격자가 세션을 하이재킹하여 사이트 사용자 인 것처럼 가장하는 재생 공격에 대한 추가 보호 기능을 제공하며 사용자로부터 지불을 수락하기 전에 가장 적절한 수표입니다.
나는 사기로부터 보호하기위한 메커니즘으로 사용자 유효성 확인에만 의존하지 않을 것입니다. Google Commerce platform과 같은 안전한 지불 시스템을 사용하고 the best practices for commerce을 따라야합니다.
캐시 된 자격 증명이 초기화 될 때마다 OAuth2 v2 끝점을 사용하여 토큰을 확인해야합니다. 이미 검증되었고 서버 측에 저장된 캐시 된 신임 정보를 사용해야하므로 모든 요청을 확인하는 것이 약간 과한 것으로 보입니다. 대부분의 경우 액세스 토큰을 업데이트 할 때 검사를 수행 할 수 있지만 새로 고침 토큰을 신뢰하는 경우 계정을 만들 때 검사를 수행하고 새로 고침 토큰을 설정하면 충분히 안전해야합니다.
다음 단계는 계정 생성시 사용자 ID 확인에 추가하여 수행됩니다
연결된 게시물에서 언급했듯이 the Google+ quickstarts의 샘플 코드는 계정 인증을 위해 다양한 프로그래밍 언어로 이러한 검사를 수행하는 방법을 충분히 보여줍니다. HTML/JS 클라이언트 내에서
다음 코드를 보여줍니다 경우 사용자 ID (값, 특수한 캐릭터 "나"반대)의 Google+ 사용자 ID 확인하기 위해 연결 방법에 전달하는 검색됩니다 :
var request = gapi.client.plus.people.get({'userId' : 'me'});
request.execute(function(profile) {
$('#profile').empty();
if (profile.error) {
$('#profile').append(profile.error);
return;
}
helper.connectServer(profile.id);
$('#profile').append(
$('<p><img src=\"' + profile.image.url + '\"></p>'));
$('#profile').append(
$('<p>Hello ' + profile.displayName + '!<br />Tagline: ' +
profile.tagline + '<br />About: ' + profile.aboutMe + '</p>'));
if (profile.cover && profile.coverPhoto) {
$('#profile').append(
$('<p><img src=\"' + profile.cover.coverPhoto.url + '\"></p>'));
}
});
... 다음 코드는 전달되는 Google+ ID를 보여줍니다.다음과 같이 자바 샘플에서이 검사를 수행
connectServer: function(gplusId) {
console.log(this.authResult.code);
$.ajax({
type: 'POST',
url: window.location.href + '/connect?state={{ STATE }}&gplus_id=' +
gplusId,
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
console.log(result);
helper.people();
},
processData: false,
data: this.authResult.code
});
}
관련 코드는 다음과 같습니다
샘플에서
// Check that the token is valid.
Oauth2 oauth2 = new Oauth2.Builder(
TRANSPORT, JSON_FACTORY, credential).build();
Tokeninfo tokenInfo = oauth2.tokeninfo()
.setAccessToken(credential.getAccessToken()).execute();
// If there was an error in the token info, abort.
if (tokenInfo.containsKey("error")) {
response.status(401);
return GSON.toJson(tokenInfo.get("error").toString());
}
// Make sure the token we got is for the intended user.
if (!tokenInfo.getUserId().equals(gPlusId)) {
response.status(401);
return GSON.toJson("Token's user ID doesn't match given user ID.");
}
// Make sure the token we got is for our app.
if (!tokenInfo.getIssuedTo().equals(CLIENT_ID)) {
response.status(401);
return GSON.toJson("Token's client ID does not match app's.");
}
// Store the token in the session for later use.
request.session().attribute("token", tokenResponse.toString());
return GSON.toJson("Successfully connected user.");
} catch (TokenResponseException e) {
response.status(500);
return GSON.toJson("Failed to upgrade the authorization code.");
} catch (IOException e) {
response.status(500);
return GSON.toJson("Failed to read token data from Google. " +
e.getMessage());
}
는, 클라이언트 ID는 구글 API 콘솔에서 와서 응용 프로그램에 대한 별개의 것입니다.
페이스 북 API로 표준화 된 방법으로 signed_request 매개 변수를 사용하는 것이지만, Google에 상응하는 매개 변수가없는 것 같아 관련 질문을 게시했습니다. http://stackoverflow.com/questions/15395142/does-google-javascript-api-have-an-equivalent-to-facebooks-signed-request –