2017-05-18 1 views
1

Parse-server를 기반으로 응용 프로그램을 개발 중이며 소셜 로그를 제공하고 싶습니다. 이 안내서는 설명서 http://docs.parseplatform.org/js/guide/#linking-users에 있습니다.Parse-server social login

Google에서 소셜 로그인을 구현하기 시작했습니다. 나는 단계를 수행 않았다

1) 내가 (로그인에 user._linkWith 기능을 클라이언트 측에서 hello.js에 의해 인증을 호출 않았다

var api = new ParseServer({ 
... 
    auth:{ 
     google: {} 
    }, 
... 
}); 

2) ParseServer 설정 선)

다음 추가 그것을 디버깅시
hello.init({ 
    google: 'My Google id' 
}); 

hello.on('auth.login', function(auth) { 
    // Call user information, for the given network 
    hello(auth.network).api('me').then(function(r) { 
    const user = new Parse.User(); 
    user._linkWith(auth.network, auth.authResponse).then(function(user){ 
     console.log('You are logged in successfully.'); 
    }); 
    }); 
}); 

는 I 제공자 객체 준비 때 _linkWith() 함수에 실패하였습니다. 모든 공급자를 저장해야하는 개체 AuthProviders는 비어 있습니다. 그것 때문에 문 공급자 = authProviders [ '구글'];은 정의되지 않은 상태가됩니다. 호출하기 provider.authenticate (...);은 "정의되지 않은 속성 '인증을 읽을 수 없습니다."

무엇이 잘못되었거나 잘못 되었나요?

답장을 보내 주셔서 감사합니다.

Honza는

답변

1

당신은 AuthenticationProvider에 등록 했습니까? 당신은이 작업을 수행하는 방법에 대한 단위 테스트에서 예를 찾을 수 있습니다 나는 또한이 오류를 얻었고, _linkWith (제공, 옵션) 소스 코드를보고

https://github.com/parse-community/parse-server/blob/5813fd0bf8350a97d529e5e608e7620b2b65fd0c/spec/AuthenticationAdapters.spec.js#L139

+0

이 옵션은 "ID"와 함께 "authData"필드를 가질 수 (구문 분석 JS 가이드의 예와는 달리) 보인다 자격 증명을 내부 중첩 :

내가 사용하고 코드의 조각이다 그것. 그렇지 않은 경우이 대답이 적용됩니다. 나는 번들 된 FacebookUtils에서 Facebook을위한 예제를 발견했다. https://github.com/parse-community/Parse-SDK-JS/blob/master/src/FacebookUtils.js를 참조한다. 다른 써드 파티 인증 공급자? Parse Server JavaScript 가이드는 authenticationProvider 등록을 완전히 언급하지 못합니다. –

0

. optionsauthData 필드가 있는지 확인합니다 (차례로 id 및 자격 증명이 있어야 함). 그렇다면 options.authData을 사용합니다. 그렇지 않으면 이전 답변에서 언급 한 이전에 등록 된 인증 공급자를 찾는데 다시 실패합니다.

const authData = { 
    "id": profile.getId(), 
    "id_token": id_token 
} 
const options = { 
    "authData": authData 
} 
const user = new Parse.User(); 
user._linkWith('google', options).then(function(user) { 
    console.log('Successful user._linkWith(). returned user=' + JSON.stringify(user)) 
}, function(error) { 
    console.log('Error linking/creating user: ' + error) 
    alert('Error linking/creating user: ' + error) 
    // TODO handle error 
}) 
관련 문제