首页> 实战笔录 >软件配置 软件配置
Google一站式登录网站登录(JavaScript SDK)
作者:小萝卜 2019-06-05 【 第三方登录 Google 】 浏览 3003
简介Google一站式登录网站登录(JavaScript SDK)官网:https://developers.google.com/identity/sign-in/web/一、创建应用a、去谷歌控制台创建应用
Google第三方网站登录(JavaScript SDK)
官网:https://developers.google.com/identity/sign-in/web/
一、创建应用
a、去谷歌控制台创建应用
网址:https://accounts.google.com/signin/v2/identifier?service=cloudconsole&passive=1209600&osid=1&continue=https%3A%2F%2Fconsole.developers.google.com%2Fproject%2F_%2Fapiui%2Fapis%2Flibrary%3Fref%3Dhttps%3A%2F%2Fblog.csdn.net%2Fzh_rey%2Farticle%2Fdetails%2F79013290&followup=https%3A%2F%2Fconsole.developers.google.com%2Fproject%2F_%2Fapiui%2Fapis%2Flibrary%3Fref%3Dhttps%3A%2F%2Fblog.csdn.net%2Fzh_rey%2Farticle%2Fdetails%2F79013290&flowName=GlifWebSignIn&flowEntry=ServiceLogin
b、应用配置如图所示
点击菜单按钮-->API和服务-->证书-->鼠标右键VantageFX Web客户端 做如下配置
1)、授权的jacasvript起源 : 一般是网址
2)、授权重定向url :当前页面的url
二、自定义登录和注销
< button id="customBtn" type="button">Google登录< /button>
< button onclick="signOut();" type="button">Sign out< /button>
< script src="https://apis.google.com/js/api:client.js">< /script>
var googleUser = {};
var startApp = function() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'xxxx', //客户端ID
cookiepolicy: 'single_host_origin',
scope: 'profile' //可以请求除了默认的'profile' and 'email'之外的数据
});
attachSignin(document.getElementById('customBtn'));
});
};
function attachSignin(element) {
auth2.attachClickHandler(element, {},
function(googleUser) {
var profile = auth2.currentUser.get().getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
},
function(error) {
console.log(JSON.stringify(error, undefined, 2));
});
}
startApp();
//注销
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function() {
alert('用户注销成功');
});
}
很赞哦! (0)
相关文章
- ckeditor增加编辑代码功能--使用官方推荐Code Snippet插件
- SourceTree提交vue3-element-admin代码到仓库报错quotepath=false --no-optional-locks commit -q
- composer切换国内或国外源
- Git安装和基本使用
- linux下如何查看80端口占用情况?是被哪个进程占用?如何终止?
- Robots.txt文件的作用及定义方法
- OneinStack一键安装网站欢迎后配置使用Redis
- 命令行杀死进程
- 为什么使用WampServer切换PHP版本后通过cmd查看PHP版本显示的还是之前版本
- CKfinder开启图片上传后自动添加水印(PHP)