我可以从Blazor客户端中的AuthenticationStateProvider访问我的ID令牌吗?

时间:2020-08-04 21:16:44

标签: authentication blazor msal

我正在尝试访问Azure AD提供的ID令牌。我确实需要访问签名和所有声明。

我可以轻松地访问AuthenticationStateProvider,然后从中获取用户。 User属性中包含所有声明,但仅此而已。我不知道如何访问其余的ID令牌。

这是我在blazor页面上后面的代码中使用的代码:

def getDbData(connection,table):
    with connection: 
        cur = connection.cursor()
        cur.execute(f"SELECT * FROM {table}")
        rows = cur.fetchall()

    if len(rows) > 0:
        logging.info(f'Got {len(rows)} entries from {table} SQL table!')
        connection.commit()
        for row in rows:
            logging.info(f'do something with each row')
    else:
        logging.info(f'Did not get any results from {table} SQL table!')
        connection.commit()


connection = pymysql.connect(host='hostname',user='SA',password='Passw',db='database',charset='utf8',use_unicode=True,cursorclass=pymysql.cursors.DictCursor)

dbindex = getDbData(connection,"dbTable")

我只是以字符串形式返回列表,以查看要获取的数据。

此外,我的引导程序如下所示:

[Inject]
AuthenticationStateProvider authenticationState { get; set; }

public async Task<string> GetIDTokenAsync()
{
    var authState = await authenticationState.GetAuthenticationStateAsync();

    return string.Join(", ", authState.User.Claims.ToList());
}

打开网站后,我使用RemoteAuthenticatorView组件登录。登录后,我需要访问ID令牌。此外,我只想澄清一下,我不是在寻找访问令牌。我不需要任何作用域,因此没有访问令牌。我的目标是获取ID令牌并将其传递给我的API,API可以在其中验证ID令牌,然后发出其自己的访问令牌。

0 个答案:

没有答案