2017-12-12 21 views
0

私はDrupalからAngularを前面に使用してアクセストークンを受け取ろうとしています。エラー:「invalid_grant」角度5

ngOnInit() { 

    this.testAuthSite() 
    .subscribe(
    data => { console.log(data); }, 
    error => { console.log(error); } 
    ); 
} 

// Multiple - Returns the list of all companies available for this user 
testAuthSite() { 
    const body = { 
    grant_type: 'password', 
    client_id : '61705f72-xxx-xxx-xx', 
    client_secret: 'admin', 
    username: 'angular', 
    password: 'admin', 
    scope: null 
    }; 
    const options: any = { 
    headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') 
}; 

    return this.http.post(ApiURI, body, options); 

}

私は郵便配達してみました、それが動作します。

enter image description here

私はscopeキーの""nullの両方を試してみました。どちらも動作しません。

私はこのエラーを取得しています:

error: 
    error:"invalid_grant" 
    hint:"Check the configuration to see if the grant is enabled." 
    message:"The provided authorization grant (e.g., authorization code, 
    resource owner credentials) or refresh token is invalid, expired, revoked, 
    does not match the redirection URI used in the authorization request, or 
    was issued to another client." 
    __proto__:Object 
    headers:HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} 
    message:"Http failure response for http://ecd2- 
    oes.dev.ee.citeoeo.com/oauth/token: 400 Bad Request" 
    name:"HttpErrorResponse" 
    ok:false 
    status:400 
    statusText:"Bad Request" 
    url:"http://xxxx.com/oauth/token" 

そして、ここでは、私が送信してるかの詳細です:

enter image description here

はあなたの助けをありがとう!

答えて

1

私は問題を解決することができました。

POSTリクエストは期待されていませんでした.JsonではなくFormDataです。だから私はJsonをFormDataに変換しなければならなかった:

testAuthSite() { 
    const body = { 
    'grant_type': 'password', 
    'client_id' : '61705f72-c913-43bf-b915-d679e82e8d58', 
    'client_secret': 'admin', 
    'username': 'angular', 
    'password': 'admin', 
    'scope': '' 
    }; 

    const myFormData = this.getFormData(body); 

    return this.http.post(authURL, myFormData); 
} 

getFormData(object) { 
    const formData = new FormData(); 
    Object.keys(object).forEach(key => formData.append(key, object[key])); 
    return formData; 
} 
関連する問題