2017-01-31 3 views
1

OKTA의 개발자 계정에서 작업하고 있습니다.OKTA - OAuthError : redirect_uri 매개 변수의 값이 잘못되었습니다.

나는 아주 간단한 SPA 응용 프로그램을 사용하여 OKTA에서 JWT를 얻으려고합니다.

  1. 나는 authClient.signIn ({})로 로그인하고 내가 authClient.token.getWithoutPrompt를 호출 할 수 있어야하는 세션 토큰과 transaction.sessionToken/

  2. 을 ({반환 })하지만 그 코드에 도달 할 수는 없습니다.

다음과 같은 오류가 발생합니다. OAuthError : redirect_uri 매개 변수의 값이 잘못되었습니다.

마침내 JWT를 다시 얻을 수 있도록이 OAuth 오류를 어떻게 초과 할 수 있습니까? OKTA GIT에 대한 예제를 시도했지만 아무 것도 얻을 수 없습니다. 당신의 redirectUri이 당신의 Okta Developer organization에 승인 된 리디렉션 URI를에 포함되어 같이

function getJWT() 
{ 
    var orgUrl = 'https://MYXXXXXXX.oktapreview.com'; 
    var keyID = "MY CLIENT ID"; 

    var user = "MYUSER ID"; 
    var pwd = "MY PASWORD" 

    var appScope = ['openid', 'email', 'profile', 'phone', 'groups']; 

    var authClient = new OktaAuth({url: orgUrl, clientId: keyID,}); 

    $('#tokendiv').html(''); 

    authClient.signIn({ 
      username: user, 
      password: pwd, 
      redirectUri: "http://localhost:5656/test.html" //THIS IS SETUP IN MY OKTA ID 
     }) 
     .then(function(transaction) { 
      if (transaction.status === 'SUCCESS') { 
      authClient.session.setCookieAndRedirect(transaction.sessionToken); // Sets a cookie on redirect 
      console.log(transaction.sessionToken); 
      $('#tokendiv').append('<h4>Session Token</h4>' + transaction.sessionToken); 

      /// THIS IS NEVER REACHED, I Always Get OAuthError: Illegal value for redirect_uri parameter. 
      authClient.token.getWithoutPrompt({  
       responseType: 'id_token', // or array of types    
       scopes: appScope, 
       sessionToken: transaction.sessionToken 
      }) 
       .then(function(res) { 
       console.log("JWT: " + jwt); 
       $('#tokendiv').append('<h4>JWT</h4>' + res.idToken); 
       }) 
       .fail(function(err) { 
       console.log("ERROR " + err); 
       $('#tokendiv').append('<h4>Error</h4>' + err); 
       })       

      } else { 
      throw 'We cannot handle the ' + transaction.status + ' status'; 
      } 
     }) 
     .fail(function(err) { 
      console.error(err); 
     }); 
} 
+0

authClient.token.getWithoutPrompt ({})를 제거하면 더 이상 오류가 발생하지 않지만 JWT를 얻으려면 해당 메소드가 필요하다는 것을 발견했습니다. –

답변

1

는 한, 당신은 그 오류를 수신 할 수 없습니다.

아래 id_token은 성공적으로 localhost:5656에서 돌아갈 수있었습니다.

<!-- index.html --> 

<html> 
    <body> 
     <button onClick="getJWT()">Button</button> 
     <div id="tokendiv"></div> 
    </body> 
</html> 

<script> 
    function getJWT(){ 
     var orgUrl = 'https://{{org}}.oktapreview.com'; 
     var keyID = "{{clientId}}"; 

     var user = "{{user}}"; 
     var pwd = "{{password}}" 

     var appScope = ['openid', 'email', 'profile', 'phone', 'groups']; 

     var authClient = new OktaAuth(
      { 
       url: orgUrl, 
       clientId: keyID, 
       redirectUri: "http://localhost:5656/index.html" 
      }); 

     $('#tokendiv').html(''); 

     authClient.signIn({ 
       username: user, 
       password: pwd, 
     }) 
     .then(function(transaction) { 
      if (transaction.status === 'SUCCESS') { 
       authClient.token.getWithoutPrompt({  
        responseType: 'id_token', // or array of types    
        scopes: appScope, 
        sessionToken: transaction.sessionToken 
       }) 
       .then(function(res) { 
        $('#tokendiv').append('<h4>JWT</h4>' + res.idToken); 
        console.log("JWT: " + JSON.stringify(res)); 
       }) 
       .fail(function(err) { /* err */ })       
      } else { /* throw error */ } 
     }) 
     .fail(function(err) { /* err */ }); 
    } 
</script> 
+0

나는 언급했다. redirectUri : "http : // localhost : 5656/test.html"// OKTA에서 설정 됨 –

+1

확인하고 싶습니다. OktaAuth는 구성 객체에 지정된 redirectUri가 아니라 현재 브라우저 URL을 보내고 있습니다. 리디렉션을 설정하는 방법을 보여주기 위해 내 대답을 업데이트했습니다. – jmelberg

+0

업데이트로 문제가 해결되었습니다. authClient.signIn 아래에 redirectUri가 있었지만 (당신이 보았 듯이) var authClient = new OktaAuth 아래에 있어야했습니다. 고맙습니다! –

관련 문제