My API returns a PDF document for which I need my user to be authenticated. On my AngularJS application the user clicks on a link that calls a function:
<a ng-click="getBankDetails()">Print bank details</a>
Controller:
$scope.getBankDetails = ->
$http.get(ENV.apiEndpoint + "/api/v1/users/get_bank_details", { headers: { 'Accept': 'application/pdf' }, responseType: 'arraybuffer' })
.success((resp) ->
file = new Blob([resp], {type: 'application/pdf'})
fileURL = URL.createObjectURL(file)
window.open(file);
)
but this doesn't work.
I have tried removing the authentication need on the API. The method above still doesn't work, but if I do
window.open(ENV.apiEndpoint + "/api/v1/users/get_bank_details")
that works. Not really helpful except to confirm that my API works fine.
I'm using ng-token-auth for authentification
it's stored in a cookie as I'm not using cordova here
$authProvider.configure
apiUrl: ENV.apiEndpoint
storage: if _.isUndefined(window.cordova) then "cookies" else "localStorage"
Any help would be greatly appreciated