thugit-oauth
v0.1.0
Published
适用于清华大学 GitLab([Tsinghua Git](https://git.tsinghua.edu.cn/))的 OAuth 认证库,支持获取访问令牌和用户信息。其中用户信息包括**真实姓名**、**学号**、用户名和邮箱。
Downloads
110
Readme
thugit-oauth
适用于清华大学 GitLab(Tsinghua Git)的 OAuth 认证库,支持获取访问令牌和用户信息。其中用户信息包括真实姓名、学号、用户名和邮箱。
使用方法
在 Tsinghua Git 上创建一个 OAuth 应用。记录其 AppID 和 Secret,并且添加一个指向你的后端服务器的 Redirect URI,例如 https://example.com/auth/callback。你的 OAuth 应用至少需要以下权限:
read_user
在后端监听这一地址,然后从 URL Query Parameters 中获取 code,并使用它来获取访问令牌:
const accessToken = await getOauthAccessToken(oauthAppId, oauthAppSecret, authorizationCode, redirectUri);在获取到访问令牌后,就可以使用它来获取用户信息了:
const userInfo = await getUserInfo(accessToken);
console.log(userInfo);