Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@divops/github-oauth
Advanced tools
CLIENT_ID = process.env.GITHUB_CLIENT_ID,
CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET,
REFERER_COOKIE_KEY = "referer",
OAUTH_COOKIE_KEY = "github-oauth",
pages/api/callback.tsx
import { gitHubOAuth } from "@divops/github-oauth";
import type { NextApiRequest, NextApiResponse } from "next";
export default async (req: NextApiRequest, res: NextApiResponse) => {
return gitHubOAuth.callback(req, res);
};
pages/login.tsx
import { gitHubOAuth } from "@divops/github-oauth";
import { GetServerSideProps } from "next";
export const getServerSideProps: GetServerSideProps = async (context) => {
return gitHubOAuth.redirectToGitHubAuthPage(context.req, context.res);
};
export default () => {
return <></>;
};
pages/api/user.tsx
import { gitHubOAuth } from "@divops/github-oauth";
import type { NextApiRequest, NextApiResponse } from "next";
import axios from "axios";
export default async (req: NextApiRequest, res: NextApiResponse) => {
const githubOauth = gitHubOAuth.findGitHubToken(req);
if (!githubOauth) {
return res.status(401).json({ message: "Unauthorized" });
}
try {
const { data } = await axios("https://api.github.com/user", {
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${githubOauth}`,
},
});
return res.json({ data });
} catch (error: any) {
return res.status(401).json({ message: "Unauthorized" });
}
};
FLOW
1. www.creco.services/github-editor/login 에서 로그인 버튼을 클릭
2. app.divops.kr/login/test-login 으로 이동됨
3. ☝️https://github.com/login/oauth/authorize 으로 이동시켜서 인증하게함
4. 인증 완료 후, https://app.divops.kr/login/callback 으로 이동
5. callback 페이지에서 code를 읽고 /login/api/user-token 를 호출
6. /login/api/user-token 에서는 POST /login/oauth/access_token 으로 accessToken을 구해서 header 로 내려줌
7. 응답 중 accessToken 를 code라는 쿼리 파라미터로 들고 www.creco.services/github-editor/login 로 돌아감
8. /github-editor/login 에서는 code 쿼리파라미터를 가지고 POST `https://app.divops.kr/login/api/set-token` 을 요청하는 예시 API 를 호출
FAQs
Unknown package
The npm package @divops/github-oauth receives a total of 5 weekly downloads. As such, @divops/github-oauth popularity was classified as not popular.
We found that @divops/github-oauth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.