In order to identify the users of my mobile application, and link their identity with a web application, I want to use Azure Active Directory accounts and catch their OID.
Actually my mobile application uses Kinvey accounts, as shown in the nativescript tutorial.
the user login:
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)
);
}
the user registration:
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)
);
}
my methods for the headers and to handle errors:
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);
}