2017-09-29 1 views
1

Azure AD OpenID 연결 프레임 워크를 사용하여 웹 기반 Java 응용 프로그램에 대한 인증 서비스를 개발 중입니다. 내가 참조하고있다 adal4j-1.2.0.jar 동작에 따라 인증이 진행 중입니다. 나는 JWT 주장을 받고 그것을 검증 할 수있다.새로 고침 토큰이 서명되지 않은 Azure AD Adal4j 토큰이 서명 됨 JWT

하지만 60 분의 세션 시간 초과가 발생하고 새로 고침 토큰을 사용하여 새 토큰 클레임을 얻으려고하면 새 토큰은 JWT 서명이되지 않습니다. 그것들은 평범한 JWT입니다.

캐싱중인 초기 새로 고침 토큰을 사용하여 토큰을 얻으려면 아래의 호출을 사용하고 있습니다. 토큰의 검증을위한

acquireTokenByRrefreshToken(refreshtoken, credential,null,null) 

, 나는 누군가가 제가 새로운 서명 토큰을 얻을 수있는 새로 고침 토큰을 상환하는 방법을 이해하는 데 도움이 될 수 있습니다

IDtokenValidator validator = new IDTokenValidator(issuer,clientID, JWSAlgo,URL) 
validator.validate(idToken, exoectedNoounce); //this line throws badjwtexception signed ID token expected 

아래와 같은 코드를 사용하고 있습니다. 또는 토큰을 사용한 후 새 토큰은 항상 Plain JWT입니다.

답변

1

토큰을 얻기 위해 암시 적 허용 플로우를 사용하고 있습니다. 인증 엔드 포인트에서 토큰을 받고 있습니다.이 플로우에서 새로 고침 토큰을 얻지 못할 것입니다. 세션 만료 후 새 토큰을 얻거나 세션이 만료되기 전에 토큰을 얻을 수있는 숨겨진 프레임.

+0

세션이 만료 된 후 새 토큰을 얻으려면이 값을 추가하십시오. 리소스 (URL)는 Azure AD에 응답 URL로 등록 된 것과 동일해야합니다. 그러나 세션이 만료되면 사용자는 다른 URL에있을 수 있습니다. 따라서 새로운 요청이 제출되면 응답 URL이 일치하지 않는다는 오류 페이지가 표시됩니다. –

+0

이 경우 코드 부여 흐름 또는 클라이언트 자격 증명 흐름을 사용할 수 있습니다. 먼저 사용자의 유효성을 검사하여 승인 코드를 가져온 다음이 코드를 클라이언트 비밀번호와 함께 보내 토큰 + 새로 고침 토큰을 얻습니다. 사용중인 java 라이브러리에는 코드 부여 흐름을 호출하는 메소드가 있습니다. –

0

official doc을 참조하여 access tokenrefresh tokencode grant flow으로 획득 할 수 있습니다.

실제로 adal4j의 메소드는 HTTP REST API을 통해 구현되므로 아래 코드를 참조하여 AuthorizationCode을 요청할 수 있습니다.

public static void getAuthorizationCode() throws IOException { 

     String encoding = "UTF-8"; 
     String params = "client_id=" + clientId 
       + "&response_type=" + reponseType 
       + "&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F" 
       + "&response_mode=query" 
       + "&resource=https%3A%2F%2Fgraph.windows.net" 
       + "&state=12345"; 
     String path = "https://login.microsoftonline.com/" + tenantId + "/oauth2/authorize"; 
     byte[] data = params.getBytes(encoding); 
     URL url = new URL(path); 
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
     conn.setRequestMethod("POST"); 
     conn.setDoOutput(true); 
     conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
     conn.setRequestProperty("Content-Length", String.valueOf(data.length)); 
     conn.setConnectTimeout(5 * 1000); 
     OutputStream outStream = conn.getOutputStream(); 
     outStream.write(data); 
     outStream.flush(); 
     outStream.close(); 
     System.out.println(conn.getResponseCode()); 
     System.out.println(conn.getResponseMessage()); 

     BufferedReader br = null; 
     if (conn.getResponseCode() != 200) { 
      br = new BufferedReader(new InputStreamReader((conn.getErrorStream()))); 
     } else { 
      br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); 
     } 
     System.out.println("Response body : " + br.readLine()); 
    } 

그런 다음 당신은 당신이있어 AuthorizationCode를 사용하여 access token를 얻을 수 아래의 코드를 사용하여 새로 고침 코드를 얻을 수 있습니다.

public static void getToken(String refreshToken) throws IOException { 

     String encoding = "UTF-8"; 
     String params = "client_id=" + clientId + "&refresh_token=" + refreshToken 
       + "&grant_type=refresh_token&resource=https%3A%2F%2Fgraph.windows.net"; 
     String path = "https://login.microsoftonline.com/" + tenantId + "/oauth2/token"; 
     byte[] data = params.getBytes(encoding); 
     URL url = new URL(path); 
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
     conn.setRequestMethod("POST"); 
     conn.setDoOutput(true); 
     conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
     conn.setRequestProperty("Content-Length", String.valueOf(data.length)); 
     conn.setConnectTimeout(5 * 1000); 
     OutputStream outStream = conn.getOutputStream(); 
     outStream.write(data); 
     outStream.flush(); 
     outStream.close(); 
     System.out.println(conn.getResponseCode()); 
     System.out.println(conn.getResponseMessage()); 

     BufferedReader br = null; 
     if (conn.getResponseCode() != 200) { 
      br = new BufferedReader(new InputStreamReader((conn.getErrorStream()))); 
     } else { 
      br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); 
     } 
     System.out.println("Response body : " + br.readLine()); 
    } 

희망이 있습니다.

+0

감사합니다. 'acquireTokenByRrefreshToken (refreshtoken, credential, resource, null)' 을 호출하여 새 access_token, Id_token 및 refresh_token을 사용할 수 있지만 세션 객체에서 새 토큰을 사용하는 방법을 알 수는 없습니다. 60 분 후에 잃어 버리는 세션 객체에 몇 가지 매개 변수를 설정하고 있습니다. 따라서 새 토큰을 추가하려면 다시 추가해야합니다. –

관련 문제