Last active
July 17, 2020 09:22
-
-
Save hmmhmmhm/aa5ed7b3f26e88684156c4771354b731 to your computer and use it in GitHub Desktop.
NAVER Login for Backend CSR 네이버 아이디 로그인 자바스크립트 예제 예시 Node.JS 이렇게 해놓으면 구글에서 검색이 되려나
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let clientId = '' | |
let clientSecret = '' | |
let token = '' | |
let randomId = '' // 클라이언트에게 전달될 값 | |
const naverLogin = async () => { | |
let accessTokenRequestURL = `https://nid.naver.com/oauth2.0/token?client_id=${clientId}&client_secret=${clientSecret}&grant_type=authorization_code&state=${randomId}&code=${token}` | |
let auctualTokenRequestResponse = await axios.get( | |
accessTokenRequestURL | |
) | |
if (auctualTokenRequestResponse.data) { | |
let accessToken = | |
auctualTokenRequestResponse.data.access_token | |
let response = await axios.get( | |
'https://openapi.naver.com/v1/nid/me', | |
{ | |
headers: { Authorization: `Bearer ${accessToken}` }, | |
} | |
) | |
} | |
if (response.data) { | |
//console.log('NAVER OK!') | |
//console.log(JSON.stringify(response.data)) | |
/** | |
resultcode: "00" | |
message: "success" | |
response: | |
id: "1234" | |
nickname: "" | |
profile_image: "" | |
age: "10-20" | |
gender: "M" | |
email: "blabla@naver.com" | |
name: "이름름" | |
birthday: "01-01" | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment