为了识别我的移动应用程序的用户并将其身份与Web应用程序关联,我想使用Azure Active Directory帐户并捕获其OID。
实际上,我的移动应用程序使用Kinvey帐户,如nativescript教程中所示。
用户登录:
login(user: User) {
return this.http.post(
Config.apiUrl + "user/" + Config.appKey + "/login",
JSON.stringify({
username: user.email,
password: user.password
}),
{ headers: this.getCommonHeaders() }
).pipe(
map(response => response.json()),
tap(data => {
Config.token = data._kmd.authtoken
}),
catchError(this.handleErrors)
);
}
用户注册:
register(user: User) {
if (!user.email || !user.password) {
return throwError("Please provide both an email address and password.");
}
return this.http.post(
Config.apiUrl + "user/" + Config.appKey,
JSON.stringify({
username: user.email,
email: user.email,
password: user.password
}),
{ headers: this.getCommonHeaders() }
).pipe(
catchError(this.handleErrors)
);
}
我的标头方法和处理错误的方法:
getCommonHeaders() {
let headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Authorization", Config.authHeader);
return headers;
}
handleErrors(error: Response) {
console.log(JSON.stringify(error.json()));
return Observable.throw(error);
}