1.新建google账号,
最后一步要使用手机号,好像有些手机号不能验证,最好使用手机号已使用10年以上的
可能google对中国的号段已停止维护,一直使用十几年前的号段
2.打开google的个人云管理
地址:https://console.cloud.google.com/projectcreate?previousPage=%2Fwelcome%3Fproject%3Dproven-center-436608-p7&organizationId=0
新建项目
3.OAuth配置,我选的外部应用
4.添加凭据
“已获授权的 JavaScript 来源”,我的理解是打开授权的发起网页必须是这域名下
“已获授权的重定向 URI”,这个是授权完成后会回调的网址(就是你希望接受google返回信息的网址,信息会加载在URI后面比如“?token_type=Bearer&expires_in=3599&scope=profile%20https”)
5.打开的授权页
地址是:https://oop.com/ 必须是https开头或者localhost
根目录下的https://oop.com/index.html,也可以是其他网址
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
google oauth start
<button style="background-color: #0b846e" onclick="oauthSignIn()" >google OAuth2</button>
</body>
<script type="text/javascript">
/*
* Create form to request access token from Google's OAuth 2.0 server.
*/
function oauthSignIn() {
// Google's OAuth 2.0 endpoint for requesting an access token
var oauth2Endpoint = 'https://accounts.google.com/o/oauth2/v2/auth';
// Create <form> element to submit parameters to OAuth 2.0 endpoint.
var form = document.createElement('form');
form.setAttribute('method', 'GET'); // Send as a GET request.
form.setAttribute('action', oauth2Endpoint);
// Parameters to pass to OAuth 2.0 endpoint.
var params = {'client_id': '757165799834-mditg6fe74hvoti9h5qaipqp3dsti9q2.apps.googleusercontent.com',
'redirect_uri': 'https://oop.com/google/oauth.html',
'response_type': 'token',
'scope': 'https://www.googleapis.com/auth/userinfo.profile',
'include_granted_scopes': 'true',
'state': 'pass-through value'};
// Add form parameters as hidden input values.
for (var p in params) {
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', p);
input.setAttribute('value', params[p]);
form.appendChild(input);
}
// Add form to page and submit it to open the OAuth 2.0 endpoint.
document.body.appendChild(form);
form.submit();
}
</script>
</html>
打开浏览器 nginx 配置和hosts要配置好
6.点击“google OAuth2” 到达交互页
7.到达“已获授权的重定向 URI”
无参地址: https://oop.com/google/oauth.html
google给添加的参数地址:https://oop.com/google/oauth.html#state=pass-through%20value&access_token=ya29.a0AcM612whL6KHpH5ADzGqwVSb5lXEv0Ce4btPxNJ4Zomf-p5npflrZyvNBouTc9wJz91gz6IX3iE6FYqr8_jVkrH-Wm1HZUWpxoJci8pMknEqu1sDH9a2cNAVMIQ2JLkDk_s6wdKuOZ4zWTBXpvmgaAKiDPxHj7VerQaCgYKAUASARASFQHGX2MiFBdJp0AH7IMOThpjF92jtQ0169&token_type=Bearer&expires_in=3599&scope=profile%20https