登录到远程API服务器后,获取access_token后,我尝试为所有后续的ajax调用设置授权头:
.done(function (result) {
console.log("GOT AUTHORIZATION");
amplify.store( "tokens", { access_token: result.access_token, refresh_token: result.refresh_token, token_type: result.token_type, expires_in: result.expires_in });
var authorization = 'Bearer ' + amplify.store( "tokens" ).access_token;
console.log(authorization);
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', authorization);
}
});
在控制台上我能看到:
GOT AUTHORIZATION login.js:34
Bearer 6b7578772fbb4178793100651f2234de840237fe
但是随后的所有ajax调用都没有正确设置头部:
https://macmini.local:8000/Categories?_=1381758170726
由于头部没有找到 access_token(服务器控制台...),因此无法成功。
{ code: 400,
error: 'invalid_request',
error_description: 'The access token was not found',stack: undefined }
saveAccessToken: 6b7578772fbb4178793100651f2234de840237fe, client_id: 1234567890, user_id: 1
我尝试在ajax调用中修改标题,但没有成功。