【发布时间】:2019-06-01 23:08:36
【问题描述】:
我正在发布登录详细信息并接收 access_token 以进行登录授权,但将令牌发送回 Web api 以进行登录批准失败
getToken() {
let headers = new Headers();
headers.append('Accept', 'application/x-www-form-urlencoded');
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
let name = this.UserName,
psd = this.Password;
let data = 'grant_type=password&UserName=' + name + '&Password=' + psd
return new Promise((resolve, reject) => {
this.http.post('http://localhost:65882/Token', data, { headers: headers })
.toPromise()
.then((data: any) => {
this.results = data; // get data in result variable
this.token = JSON.stringify(this.results); // then convert data to json string
console.log(this.token);
this.allData = JSON.parse(this.token); // parse json data and pass json string
console.log('token' + this.allData['_body{access_token}']); // got result of particular string
})
.catch((error) => {
console.log(error.status);
console.log(JSON.stringify(error));
});
});
}
【问题讨论】:
-
能否添加登录端点的API详细信息?
-
public override Task TokenEndpoint(OAuthTokenEndpointContext context) { foreach (KeyValuePair<string, string> property in context.Properties.Dictionary) { // Adding. context.AdditionalResponseParameters.Add(property.Key, property.Value); } // Return info. return Task.FromResult<object>(null); }
标签: angularjs typescript api ionic3 outlook-restapi