Oauth2 Implicit Flow with single-page-app refreshing access tokens

后端 未结 4 1424
旧时难觅i
旧时难觅i 2021-02-01 03:29

I am using Thinktecture AuthorizationServer (AS) and it is working great.

I would like to write a native javascript single page app which can call a WebAPI directly, how

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 03:59

    Sounds like you need to queue requests in the event that an access token expires. This is more or less how Facebook and Google do it. A simple way using Angular would be to add a HTTP Interceptor and check for HTTP401 responses. If one is returned, you re-authenticate and queue any requests that come in after until the authentication request has completed (i.e. a promise). Once that's done, you can then process the outstanding queue with the newly returned access token from your authentication request using your refresh token.

    Happy Coding.

提交回复
热议问题