@devts/authjs
v0.0.16
Published
Oauth2 Library
Downloads
32
Maintainers
Readme
AuthJS
Type-Safe Oauth Util Library
Installation
npm i @devts/authjs
Example
Github
import { Github, isError, isOk } from "@devts/authjs";
const options: Github.IOauth2Options = {
client_id: "",
client_secret: "",
redirect_uri: "",
scope: ["read:user", "user:email"]
};
const login_uri = Github.getLoginUri(options);
// request document api to login_uri
const tokens = await Github.getTokens(options)("code");
if (isError(tokens)) {
console.error(tokens.result); // this is error message from gitub api.
}
if (isOk(tokens)) {
console.log(tokens.result); // this is github token.
const user = await Github.getUser(tokens.result.access_token);
if (isOk(user)) {
const userinfo: Github.IUser = user.result;
console.log(userinfo);
}
const emails = await Github.getEmails(result.access_token);
if (isOk(emails)) {
const email_list: Github.IEmail[] = emails.result;
console.log(email_list);
}
}