WebAPI OAuth Logout - How to drop Token Cookie?

前端 未结 2 989
深忆病人
深忆病人 2021-01-24 06:21

I have a WebAPI with OAuth login configured like this:

app.UseOpenIdConnectAuthentication(
    new OpenIdConnectAuthenticationOptions
    {
        ClientId = cl         


        
相关标签:
2条回答
  • 2021-01-24 06:28

    You can't logout of the API because you're not logged in to it!

    For example, say your API uses Facebook as its OpenID authentication provider. Your user will have to log into facebook to use your API. Your API will redirect them to facebook auth server and if they are not logged in - facebook will ask them to log in.

    If the user decides to stay logged into facebook, then each time they use your API, they will not be required to login to facebook again and your middleware code will obtain a valid token for them to access your API.

    Your API can't remove the browser cookie between facebook and your user's browser so you can't log them out of facebook, so you can't stop them getting new tokens when they want.

    I don't know what OpenID provider you use but I would think the above applies for any.

    You can log out of MVC app as it would have created a cookie between you (user agent) and the MVC app when you logged in. It can delete its own cookie!

    0 讨论(0)
  • 2021-01-24 06:30

    The easiest way is for the client itself to just "forget" the token - no need to tell server about it (this is what clearing the auth cookie really is doing - making the browser remove the cookie).

    If you want the token itself to be no longer valid, than you would need to maintain a list of revoked tokens. For various reasons you may want your access tokens to be always valid but short lived and revoke refresh tokens instead.

    0 讨论(0)
提交回复
热议问题