私は、Postmanを使用して動作することがわかっている認証エンドポイントに対して認証するためにAngularを使用しようとしています。
<script type="text/javascript">
var tokenGeneratorApp = angular.module('myApp', []);
myApp.controller('AuthenticationController', function ($scope, $http) {
var ac = this;
ac.authorizationToken = null;
ac.getAuthorizationToken = function() {
$http({
method : 'POST',
url: 'https://api.myserver.net/oauth/token',
data: {
grant_type: 'password',
username: 'theUserName',
password: 'thePassword'
},
headers: {
'Content-Type': 'application/json'
}
}).then(_authenticationSuccess, _authenticationError);
};
// Private methods to handle promise results
function _authenticationSuccess(response) {
ac.authorizationToken = response.data;
ac.resultsDisplay = ac.authorizationToken;
};
function _authenticationError(response) {
ac.resultsDisplay = 'An error occured: ' + response.data;
};
});
</script>
getAuthorizationToken()
私はHttp 400バックを取得します。 response.data
オブジェクトを調べると、エラーがerror:"unsupported_grant_type"
と表示されます。 Postmanクライアントではgrant_type
をpassword
と指定しており、すべて正常に動作するため、これは私を混乱させます。
私は角度コードで何か間違っている必要があります。
お返事ありがとうございます。あなたが指示した変更を加えましたが、同じエラーが発生します。 – webworm
代わりにヘッダーを 'Content-type'に変更できますか? 'application/x-www-form-urlencoded' –
郵便配達員が使用しているものと運がないので、これも試しました。 – webworm