0.0.3 • Published 1 year ago
@jl-org/auth v0.0.3
Web 集成各大平台一键登录
安装
npm i @jl-org/authnode 版本 >= 18
谷歌登录
纯浏览器实现
import { googleLogin, clientGetGoogleUserInfo, serverGetGoogleUserInfo } from '@jl-org/auth'
/**
* 点击登录
*/
document.getElementById('googleLoginBtn')?.addEventListener('click', () => {
googleLogin({
client_id: 'your-client-id',
redirect_uri: 'your-redirect-uri',
})
})
/**
* ## 注意,此方式会暴露你的 client_secret
* 在你的 redirectUri 前端页面中获取用户信息
*/
clientGetGoogleUserInfo({
client_id: 'your-client-id',
client_secret: 'your-client-secret',
redirect_uri: 'your-redirect-uri'
})
.then(userInfo => {
console.log(userInfo)
})服务器端实现
import { serverGetGoogleUserInfo } from '@jl-org/auth'
// 省略服务器处理请求...
serverGetGoogleUserInfo({
client_id: 'your-client-id',
client_secret: 'your-client-secret',
redirect_uri: 'your-redirect-uri',
code: 'your-code'
})
.then(userInfo => {
console.log(userInfo)
})