Giter VIP home page Giter VIP logo

passport-kakao's Introduction

passport-kakao

kakao oauth2 로그인과 passport 모듈 연결체.

install

npm install passport-kakao

how to use

  • https://developers.kakao.com/ 에서 애플리케이션을 등록한다.
  • 방금 추가한 애플리케이션의 제품 설정 - 카카오 로그인에 들어가서 활성화 설정을 ON으로 한 뒤 저장한다.
  • 설정 - 일반에서, 플랫폼 추가를 누른 후 웹 플랫폼을 추가한다.
  • 웹 플랫폼 설정의 사이트 도메인에 자신의 사이트 도메인을 추가한다. (ex : http://localhost:3000)
  • 프로그램 상에서는 아래와 같이 사용한다.

clientSecret을 활성화 한 경우 해당 파라메터를 같이 넘겨줘야한다.

const passport = require('passport')
const KakaoStrategy = require('passport-kakao').Strategy

passport.use(new KakaoStrategy({
    clientID : clientID,
    clientSecret: clientSecret, // clientSecret을 사용하지 않는다면 넘기지 말거나 빈 스트링을 넘길 것
    callbackURL : callbackURL
  },
  (accessToken, refreshToken, profile, done) => {
    // 사용자의 정보는 profile에 들어있다.
    User.findOrCreate(..., (err, user) => {
      if (err) { return done(err) }
      return done(null, user)
    })
  }
))

기본 callbackPath는 /oauth 이고 https://developers.kakao.com 에서 수정할 수 있다. 하지만 callbackURL은 사이트 도메인/oauth 로 설정하는 것을 권장함. (ex : http://myhomepage.com:3000/oauth )

profile property

profile에는 아래의 property들이 설정되어 넘겨진다.

key value 비고
provider String kakao 고정
id Number 사용자의 kakao id
_raw String 사용자 정보 조회로 얻어진 json string
_json Object 사용자 정보 조회로 얻어진 json 원본 데이터

simple sample

설치 & 실행

  1. ./sample/server/app.tsappKeyhttps://developers.kakao.com 에서 발급받은 JS appKey 값으로 셋팅.
  2. command line 에서 아래의 커맨드 실행
  3. 브라우져를 열고 localhost:3000/login 을 입력 후 이후 과정을 진행한다.
cd ./sample/server
npm install
npm start

기타

passport-oauth 모듈과 passport-facebook 모듈을 참고함.

passport-kakao's People

Contributors

aanoaa avatar cereme avatar dependabot[bot] avatar hi30000 avatar rotoshine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

passport-kakao's Issues

1.0.1버전 npm에 배포해주세요.

1.0.0으로 할 때 dist 폴더 내에 strategy.js가 소문자로 생겨서
require('./Strategy.js')할 때 맥/리눅스에서는 인식되지 않는 문제가 있습니다.

Request email and other scopes

I can only get the userId from Kakao the profile value. How to request other profile fields like email and name through passport?

Which should I use between Rest API Key and JS Key?

The comment in the code says to use the Rest apicet, as below.

image

However, the example description says to use the JS app key as shown below.

image

I don't know if it's an issue that's completely related to the above, but there was an issue like this.

  1. Create the production and development versions of the Kakao application
  2. Production Application Verifies Normal Operation with REST APT KEY
  3. 500 error when using REST APT KEY in development application
  4. I replaced REST APT KEY with JS KEY in the development application and it works fine

json.properties.nickname이 없습니다

this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
        if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }

        try {
            var json = JSON.parse(body);



            var profile = { provider: 'kakao' };
            profile.id = json.id;
            profile.username = json.properties.nickname;

            profile._raw = body;
            profile._json = json;

            done(null, profile);
        } catch(e) {
            done(e);
        }
    });

var json = JSON.parse(body); 를 로그로 찍어보면 json에 id 값 밖에 들어가 있지를 않아서
profile.username = json.properties.nickname 에서 오류가 납니다.
원래 id값만 넘어오는 것인지 아니면 카카오 개발자센터에서 제가 설정해야하는 것이 있는 지 궁금합니다.

개발자 RESTful API 중 로그아웃도 이 패키지로 이용 가능한가요?

https://kapi.kakao.com/v1/user/logout
https://developers.kakao.com/docs/js-reference#kakao_auth_loginform(settings)

위의 역할을 하는 로그아웃과 새로운 계정으로 로그인 할 수 있게 띄워주는 함수도 있나요?

router.get('/logout', isLoggedIn, (req, res) => {
    req.logout();
    req.session.destroy(() =>{
        res.redirect('/');
    });
})``

이런 식으로 passport logout 함수를 사용를 사용하면 카카오톡 로그인하기를 눌렀을 경우 아이디와 비밀번호를 받지 않고 자동로그인이 됩니다.

reverse proxy 환경에서 카카오 계정 요청 주소가 잘못 보내지는 것 같습니다.

www.abc.com:8001 같은 포트 노출을 막기 위해
IIS 웹서버 URL 재작성 기능을 사용하여 역방향 프록시를 설정하였습니다.

접속 주소에 포트 번호를 입력하고 접속해서 카카오 로그인 기능을 사용하면 정상 동작하는데
역방향 프록시 기능을 사용하여 포트 번호 없이 접속하면 404 에러가 발생합니다.

개발자 도구로 내용을 살펴 보니 역방향 프록시로 서비스할 때는 요청 주소가
아래와 같이 잘못 보내지고 있습니다.

포트 번호 사용 시-정상동작
https://kauth.kakao.com/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Fwww.bado.co.kr%3A52273%2Fauth%2Fkakao%2Fcallback&client_id=

포트 번호 없이(역방향 프록시)-404에러
http://www.bado.co.kr/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A52273%2Fauth%2Fkakao%2Fcallback&client_id=

혹시 이유나 대응 방법을 알 수 있을까요?

ReferenceError: InternalOAuthError is not defined

I used this package to handle my website's kakao login, and while trying to login with kakao, it causes error below.

ReferenceError: InternalOAuthError is not defined
at /------/node_modules/passport-kakao/lib/strategy.js:58:32
at passBackControl (/------node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage. (/------/node_modules/oauth/lib/oauth2.js:157:7)
at IncomingMessage.emit (events.js:228:7)
at endReadableNT (_stream_readable.js:1185:12)
at processTicksAndRejections (internal/process/task_queues.js:81:21)

It seems like this package is using InternalOAuthError while its not defined, and I found on the website that adding
"
var InternalOAuthError = require(‘passport-oauth2’).InternalOAuthError
"
to the library code can solve the problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.