私のPolymerプロジェクトでiron-ajaxを使用してユーザーにログインしています。ユーザーの詳細をデータベースに送信した後、ログインが成功したらトークンを返す必要があります。しかし、私は応答に問題があります。誰かが私のコードを見て、私が何が欠けているか教えてくれれば素晴らしいだろう。
現在、コンソールはreposプロパティを出力すると私を未定義に戻します。以下は私のiron-ajaxのコードとユーザーが詳細を送信したときに呼び出される関数です。 さらに、私が返そうとしているものを追加しました。ポリマーでiron-ajaxレスポンスハンドラを使用してaccess_tokenを取得できません
<dom-module id="login-form">
<template>
<iron-ajax
id="requestUser"
url="http://api.dev/oauth/token"
handle-as="json"
method="POST"
content-type="application/json"
body='{
"grant_type": "password",
"client_id": 2,
"client_secret": "KyHacYa2Q7DCTVLaDe1RSnvTlTI20CrmYb7FXujb",
"username": "[email protected]",
"password": "1111",
"scope": "*"}'
last-response="handleResponse"></iron-ajax>
</template>
<script>
Polymer({
is: 'login-form',
properties: {
repos: {
type: Array
},
},
//On-tap loginTheUser runs
loginTheUser: function() {
this.$.requestUser.generateRequest();
},
handleResponse: function (data) {
this.repos = data.details.response;
console.log(this.repos);
},
</script>
</dom-module>
次は私が返さ取得しようとトークンです:
{
"token_type": "Bearer",
"expires_in": 3155673599,
"access_token": "eyJ0eXAiOiJKV1...",
"refresh_token": "271VWcUXisybg="
}
何らかの理由でありがとう、私は詳細の代わりに詳細を持っていました。 それは修正されました! – Niklas