2017-09-12 1 views
1

AngieJs SPA에서 swagger-js/swagger-client (https://github.com/swagger-api/swagger-js)를 사용하여 TryItOut Executor를 사용하여 nodeJS 서버에 REST 요청을 보냅니다.Swagger-js로 브라우저 쿠키 활성화

인증에 PassportJS를 사용하고 있습니다. 내가 true로 설정 withCredentials 속성을 사용하여 각도의 $ HTTP 서비스를 사용하는 경우 :

$http({ 
     method: 'GET', 
     withCredentials: true, 
     url: 'http://someUrl/someRestPath/' }) 

을, 모든 확인을 작동 - 브라우저 쿠키가 제대로 설정되어, 모든 추가 요청이 성공적으로 인증됩니다.

swagger-js Executor로 전환하면 쿠키가 설정되지 않아 제대로 인증되지 않습니다. 나는 다음을 시도했다 :

var swaggerClient = new SwaggerClient(specUrl) 
    .then(function (swaggerClient) {            
     swaggerClient.http.withCredentials = true; // this activates CORS, if necessary 

설명서에 제안되었지만 이는 아무런 효과가 없다. 여권으로 인증 할 때 자격 증명을 받지만 쿠키가 설정되지 않아 더 이상의 요청이 승인되지 않습니다.

Left: cookies not being sent; Right: cookies being set

어떻게 자신감-JS를 사용하여이 동작을 사용하려면?

답변

1

해결책을 찾을 수있었습니다. Swagger-js 클라이언트의 execute 메소드를 사용하여 우리 자신의 http 메소드를 정의 할 수 있습니다.

Swagger({ url: 'some swagger specification (yaml/json)' }).then(client => { 
    client.execute({ http: $http, operationId: operationId, parameters: parameters}); 
: 당신이 당신의 자신감 클라이언트를 만들 때

angular.module('app', []).config(['$httpProvider',function ($httpProvider) { 
    $httpProvider.defaults.withCredentials = true; 
} 

: 그리고 나는 단지의 .config에서 세계적으로의 .config

import Swagger from 'swagger-client'; 

에 true로 설정 withCredentials과의 각도 $ HTTP 서비스를 사용