Oidc客户端使用用户名和密码登录

时间:2020-02-21 11:22:15

标签: reactjs asp.net-core openid-connect

我有一个登录表单,其中包含用户名和密码字段。 我想使用Oidc客户端对用户名和密码进行身份验证。这是默认情况下用于登录的方法:

     async signIn(state) {
            await this.ensureUserManagerInitialized();
            try {
                const silentUser = await this.userManager.signinSilent(this.createArguments());
                this.updateState(silentUser);
                return this.success(state);
            } catch (silentError) {
                // User might not be authenticated, fallback to popup authentication
                console.log("Silent authentication error: ", silentError);

                try {
                    if (this._popUpDisabled) {
                        throw new Error('Popup disabled. Change \'AuthorizeService.js:AuthorizeService._popupDisabled\' to false to enable it.')
                    }

                    const popUpUser = await this.userManager.signinPopup(this.createArguments());
                    this.updateState(popUpUser);
                    return this.success(state);
                } catch (popUpError) {
                    if (popUpError.message === "Popup window closed") {
                        // The user explicitly cancelled the login action by closing an opened popup.
                        return this.error("The user closed the window.");
                    } else if (!this._popUpDisabled) {
                        console.log("Popup authentication error: ", popUpError);
                    }

                    // PopUps might be blocked by the user, fallback to redirect
                    try {
                        await this.userManager.signinRedirect(this.createArguments(state));
                        return this.redirect();
                    } catch (redirectError) {
                        console.log("Redirect authentication error: ", redirectError);
                        return this.error(redirectError);
                    }
                }
            }
        }

方法是从 Login.js 调用的:

async login(returnUrl) {
        const state = {returnUrl };
        const result = await authService.signIn(state);
        switch (result.status) {
            case AuthenticationResultStatus.Redirect:
                break;
            case AuthenticationResultStatus.Success:
                await this.navigateToReturnUrl(returnUrl);
                break;
            case AuthenticationResultStatus.Fail:
                this.setState({ message: result.message });
                break;
            default:
                throw new Error(`Invalid status result ${result.status}.`);
        }
    }

现在我有一个自定义的登录表单。我将具有用户输入的用户名和密码的值,但我不知道对其进行身份验证。怎么办?

1 个答案:

答案 0 :(得分:0)

很遗憾,该库尚未支持它。

https://github.com/IdentityModel/oidc-client-js/issues/234