0

미리 서명 된 Amazon S3 URL을 가져 와서 Knox를 사용하여 해당 URL로 파일을 업로드해야하는 웹 앱을 구축하려고합니다.Angular에서 AWS로 승인 헤더를 보내지 않았습니다.

내가 아마존에 내 요청뿐만 아니라 내 아마존 키가 포함되어있는 것을 확인할 수 있습니다 나의 버킷을

<Error><Code>InvalidArgument</Code><Message>Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified</Message><ArgumentName>Authorization</ArgumentName><ArgumentValue>Bearer *****bearer token*****</ArgumentValue><RequestId>1AFD8C7FD2D7E667</RequestId><HostId>ID</HostId></Error> 

에 액세스하려고 할 때 S3 날이 오류를 제공하지만, 또한 내 인증 헤더

https://bucket.s3-eu-west-1.amazonaws.com/image.jpg?Expires=1418226249&AWSAccessKeyId=<key>&Signature=DHYCio7Oao%2BnzPWiiWkGlHb0NAU%3D 

및 헤더 인증 : 무기명

코드는

0123과 같습니다.
$http.post(image, data, {headers: { 'Authorization': null }, withCredentials: false} ).success(function (url) { 
     item.images[0] = url; 
     $http.post('/api/item', item); 
     }); 

내 도메인을 가리키는 요청에 대한 인증 토큰을 제거하려면 어떻게합니까?

감사

답변

0

당신은 Interceptors을 사용하고 그것 $ httpProvider.interceptors를 배열에 추가하여 $ httpProvider에 등록 된 서비스 공장으로 정의한다. 팩토리는 호출되고 의존성 (지정된 경우)이 삽입되어 인터셉터를 리턴합니다.

내 인증 토큰이 쿠키에 저장되어 있고이 토큰을 인증 헤더로 전달하려고한다고 가정합니다. 그래서 그것을 달성하기 위해 내가 한 일과 그것은 나를 위해 일합니다.

//Token Interceptor to intercept HTTP_AUTHORIZATION token into headers. 
App.factory('TokenInterceptor', [ '$q', '$window', '$location', function ($q, $window, $location) { 
return { 
    request: function (config) { 
     config.headers = config.headers || {}; 
     if ($window.sessionStorage.token) { 
      config.headers.Authorization = $window.sessionStorage.token; 
     } 
     return config; 
    }, 

    requestError: function(rejection) { 
     return $q.reject(rejection); 
    }, 

    /* Set Authentication.isAuthenticated to true if 200 received */ 
    response: function (response) { 
     if (response !== null && response.status === 200 && $window.sessionStorage.token && !$window.sessionStorage.isAuthenticated) { 
      $window.sessionStorage.isAuthenticated = true; 
     } 
     return response || $q.when(response); 
    }, 

    /* Revoke client authentication if 401 is received */ 
    responseError: function(rejection) { 
     if (rejection !== null && rejection.status === 401 && ($window.sessionStorage.token || $window.sessionStorage.isAuthenticated)) { 
      delete $window.sessionStorage.token; 
      $window.sessionStorage.isAuthenticated = false; 
      $location.path('/'); 
     } 

     return $q.reject(rejection); 
    } 
}; 
}]); 

당신은 당신이 지금이

$httpProvider.interceptors.push('TokenInterceptor'); 

같은 $ httpProvider.interceptors 배열에이 인증 헤더가 자동으로 추가됩니다 것입니다 어떤 HTTP 요청을 할 때마다이 인터셉터를 푸시해야보다 위의 서비스를 쓰기하면 헤더.

감사합니다.

+0

답장을 보내 주셔서 감사합니다. 일부 통화의 헤더를 제거하려고합니다. 여권인지 각도인지는 모르지만 어디서 추가 될지 모르겠습니다. –

+0

특정 위치에 TokenInterceptor에 조건을 추가 할 수 있습니다. – CrazyGeek