참고 레퍼런스 : https://been.tistory.com/14
https://developer0809.tistory.com/88
https://velog.io/@tkdfo93/%EA%B5%AC%EA%B8%80-OAuth2.0-Final-Project
https://nowonbun.tistory.com/479
https://data-jj.tistory.com/53
https://github.com/codestates/Lumiere/issues/224
useEffect(() => {
const url = new URL(window.location.href);
console.log(url);
const { hash } = url;
console.log(hash);
if (hash) {
const accessToken = hash.split('=')[1].split('&')[0];
axios
.get(
`https://www.googleapis.com/oauth2/v2/userinfo?access_token=${accessToken}`,
{
headers: {
authorization: `token ${accessToken}`,
accept: 'application/json',
},
},
)
.then((data) => {
console.log(data);
})
.catch((e) => console.log('oAuth token expired'));
}
const params = {
client_id:
'948417619672-1e90qv63tjqpgpc5ijulelhgqmib5oj2.apps.googleusercontent.com',
redirect_uri: 'http://localhost:3000',
response_type: 'code',
scope: 'https://www.googleapis.com/auth/userinfo.profile',
};
const oAuthURL = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${params.client_id}&
response_type=${params.response_type}&
redirect_uri=${params.redirect_uri}&
scope=${params.scope}`;
// 구글 소셜로그인 핸들러
const googleSocailHandler = () => {
window.location.assign(oAuthURL);
};