adal请求访问令牌

adal请求访问令牌

本文介绍了使用id_token,ADFS 2016和react-adal请求访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端应用程序,正在通过ADFS和react-adal进行身份验证,并且我的大多数应用程序都可以正常工作,但似乎找不到请求访问令牌的方法(因此刷新令牌) )和id_token,这就是我从ADFS获得的全部回报。

I've got a client side app which I'm authenticating with ADFS and react-adal and I've got most of it working but can't seem to find a way to request the access token (and therefore refresh token) with the id_token which is all I get in return from ADFS.

在React应用将用户转发到ADFS进行登录的那一刻,这将对令牌进行身份验证并我希望能够从/ adfs / userinfo端点获取userinfo(名称,姓氏,角色等),但需要不记名令牌。

At the moment the React app forwards the user to ADFS to sign in, this then authenticates the token and I want to be able to get the userinfo (Name, Surname, roles etc...) from the /adfs/userinfo endpoint but need the bearer token to do so.

当前我的componentWillMount函数是这样的

Currently my componentWillMount function looks like this

componentWillMount = () => {
    axios.get('/home/AuthenticationContext').then((response) => {
        this.adalAuthentication = new AdalAuthentication(response.data);
        if (this.adalAuthentication.authenticateToken()) { // checks if authenticated with adfs, not app
            var error = this.adalAuthentication.Instance.getLoginError();
            if (error === "") {
                axios({
                    method: 'get',
                    url: '/identity/completeLogin/' + this.adalAuthentication.Instance.getCachedToken(this.adalAuthentication.Instance.config.clientId)
                }).then((response) => { console.log(response) })
                this.setState({
                    loggedIn: true
                });
            }
            else {
                this.setState({
                    error: error
                });
            }
        }
}

T他停留在第二个axios get方法上,这在相同的原点上击中了控制器操作。

The point I'm stuck at is the second axios get method, this hit a controller action on the same origin.

    [HttpGet("completeLogin/{id_token}")]
    public async Task<IActionResult> CompleteLogin(string id_token)
    {
        var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer" + id_token);
        var response = await client.GetAsync("https://adfs.domain/adfs/userinfo");

        return View();
    }

当然,响应返回未经授权。我找不到有关如何从id_token获取访问令牌或使用Adal.js库从前端从React获取访问令牌的任何方式的信息,有人能克服吗?

Of course the response returns unauthorised. I can't find any information about how to get an access token from the id_token or any way to get an access token from React in the front end using the Adal.js library, has anyone got past this?

编辑:我从id_token获得的唯一信息如下。

the only info I get from the id_token is below.

"userName":"[email protected]",
"profile": {
    "aud":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "auth_time":1544777683,
    "exp":1544793006,
    "iat":1544789406,
    "iss":"https://adfs.domain/adfs",
    "mfa_auth_time":1544777705,
    "nonce":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "sid":"x-x-x-xx-xxxxxxxxxx-xxxxxxxx-xxxxxxxxxx-xxxx",
    "sub":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "unique_name":"T1234\\bob",
    "upn":"[email protected]"
}


推荐答案

这似乎是adal.js库的普遍问题。

This seems to be a general problem with the adal.js library.

有一种解决方法

本质上,将GET更改为POST。

Essentially, change the GET to a POST.

这篇关于使用id_token,ADFS 2016和react-adal请求访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 21:52