Identifying and authorizing users for GitHub Apps - GitHub Docs
this.GITHUB_LOGIN_URL = '<https://github.com/login/oauth/authorize?client_id=ee33270fac53d2e7b61c>'
/* <https://github.com/login/oauth/authorize?client_id=본인의clientid&선택사항&redirect_uri=본인의redircet주소> */
import React from 'react';
import styled from 'styled-components';
const LoginBtn = () => {
const loginUri = `https://github.com/login/oauth/authorize?client_id=본인의cliendid&scope=repo:status read:repo_hook user:email&redirect_uri=http://localhost:3000/callback`;
return (
<>
<GithubBtn href={loginUri}></GithubBtn>
</>
);
};
const GithubBtn = styled.a`
//생략
`;
export default LoginBtn;
유저가 로그인을 정상적으로 하면 깃헙 내 앱 등록 시 설정해둔 callback url로 redirect 되고 일시적으로 사용 할 수 있는 Autorization Code 가 url의 code 파라미터로 주어진다.
ex) <http://localhost:3000/callback?code=5e52fb85d6a1ed46a51f
>
이 autorization code 로 다시 OAuth App에 요청해서 access token을 받을 수 있지만 access token은 보안 유지가 필요하기 때문에 클라이언트에서 직접 OAuth App에 요청하기보다 해당 코드를 서버로 보내주고 서버에서 access token 요청을 하는게 적절하다.