我今天早些时候正在使用Okta身份验证库,我使用了他们网站上的Angular 2快速入门指南:“https://developer.okta.com/quickstart/#/angular/dotnet/aspnetcore”我知道浏览器已经存储了cookie。但是,当我尝试使用:“oktaAuth.getAccessToken()。accessToken”它给出了错误,当我使用“oktaAuth.getAccessToken()”时它返回错误。
import { Component } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import { OktaAuthService, OktaAuthModule } from '@okta/okta-angular';
import 'rxjs/Rx';
@Component({
selector: 'app-message-list',
template: `
<div *ngIf="messages.length">
<li *ngFor="let message of messages"></li>
</div>
`
})
export class MessageListComponent {
messages = [];
constructor(private oktaAuth: OktaAuthService, private http: Http) {
const headers = new Headers({ Authorization: 'Bearer ' + oktaAuth.getAccessToken() });
// Make request
this.http.get(
'http://localhost:58472/api/messages',
new RequestOptions({ headers: headers })
)
.map(res => res.json())
.subscribe((messages: Array<Object>) => messages.forEach(message => this.messages.push(message)));
}
}
我已多次浏览文档,但似乎无法找到任何答案。有没有人遇到过类似的问题?任何帮助都会受到很大的关注,干杯!