2017-10-27 6 views
0

REST Assured API를 사용하여 Oauth2 토큰을 생성하려고합니다. 아래는 제 코드입니다. 아래 코드가 실행될 때 잘못된 응답을 받기 때문에 생성 방법을 잘 모르겠습니다.REST ASSURED에서 새 Oauth2 토큰 생성

given().   
    .relaxedHTTPSValidation()    
    .redirects().follow(false)   
    .param("Auth URL", "https://example.com/identity/oauth/token") 
    .param("Access Token URL", "https://example2.com/identity/oauth/token") 
    .param("Client ID", "kumar") 
    .param("Client Secret", "kumar1") 
    .param("Scope", "SUBSCRIPTION_ALL") 
    .param("Grant Type", "Client Credentials") 
    .auth() 
    .preemptive().basic("kumar", "kumar1") 
    .when() 
    .redirects().follow(false) 
    .get("https://MainURI.com/oauth/token?grant_type=client_credentials&scope=read"); 

System.out.println(tokenResp.asString()); 

응답 :

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
 
<html><head> 
 
<title>302 Found</title> 
 
</head><body> 
 
<h1>Found</h1> 
 
<p>The document has moved <a href="https://example.com/404/index.html">here</a>.</p>

당신은 사용자 인증을 구현하고 같은 필터를 추가 할 필요가

답변

0

:

given(). 
     filter((requestSpec, responseSpec, ctx) -> { 
      // Your code for generating token using OAuth 
      String header = //Your service call 
      requestSpec.header("AUTH", header); 
      return ctx.next(requestSpec, responseSpec); 
     }). 
when(). 
     get("/customAuth"). 
then(). 
    statusCode(200);