2014-07-18 1 views
0

내 customAuthenticator를 사용하여 성공적으로 인증 할 수 있습니다.imy에서 imber-simple-oauth2 인증을 사용하는 방법 CustomAuthenticator

authenticate backend server로 customAuthenticator를 사용해야하는데, 요청 헤더에 client_id와 client_secret이 있어야합니다.

이와 비슷한 것.

headers: { 
      "Authorization": "Basic " + btoa(credentials.client_id + ":" + 
      credentials.client_secret) , 

      "API-KEY": window.ENV.api_key 
      }, 

하지만 난을 인증 방법이 사용하는 간단한 인증 - 파일 oauth2.js 내부 여러 유틸리티 기능이있는 참조.

다음과 같은 방법 : absolutizeExpirationTime (response.expires_in); scheduleAccessTokenRefresh (response.expires_in, expiresAt, response.refresh_token);

제 질문은 내 customAuthenticator에서 simple-auth-oauth2 내부에서이 메소드를 호출하는 방법입니다. 내 customAuthenticator 파일에 이러한 방법을 복사 할 해달라고

.....

답변

0

당신은 간단하여 OAuth 2.0 인증을 확장하는 사용자 정의 인증을 정의 할 수 있습니다. 재정의 할 수있는 유일한 방법은 예를 들어, makeRequest입니다 :

var CustomAuthenticator = Authenticators.OAuth2.extend({ 
    makeRequest: function(url, data) { 
    data.client_id  = …; 
    data.client_secret = …; 
    return this._super(url, data); 
    } 
}) 
+0

을하지만 어떻게 내가이 CLIENT_ID을 가지고 다음과 같이 헤더에 주입 client_secret하는 요청 헤더를 백엔드 서비스를 기대한다 인증 요청 header..the을 사용자 정의합니까 : 헤더 : { "인증": "기본"+ btoa (credentials.client_id + ":"+ credentials.client_secret), "API-KEY"window.ENV.api_key } – user3630294

+0

당신이 헤더를 설정하려면 '_super'를 호출하지 않고'makeRequest'를 오버라이드해야하지만'Ember. $. ajax'를 직접 호출하고'headers' 옵션을 지정해야합니다. – marcoow