0

为了识别我的移动应用程序的用户,并将他们的身份与 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);
}
4

0 回答 0