User is authenticated but where is the access token?

后端 未结 2 764
情深已故
情深已故 2021-02-06 02:34

I have a web Application which authenticates a user to an Identity Server 4, using an implicit client. I need the access token for this user so that I can make a call to anoth

2条回答
  •  粉色の甜心
    2021-02-06 03:23

    By default the OpenID Connect middleware only requests an identity token (a response_type of id_token).

    You'll need to first update your OpenIdConnectOptions with the following:

    options.ResponseType = "id_token token";
    

    You can then save the tokens to your cookie using:

    options.SaveTokens = true;
    

    And then finally, you can access the token using:

    await HttpContext.GetTokenAsync("access_token");
    

    Note that you will also need to set the AllowAccessTokensViaBrowser flag in your IdentityServer client configuration when using the implicit flow.

提交回复
热议问题