1

我们拥有一个MVC客户端,具有impicit流和CookieAuthentication。现在我们想从javascript调用另一个API(相同的STS),所以我们需要一个accesstoken。Identityserver3在隐式流程中获得访问

问题:我们如何获得accesstoken。这是我们的MVC客户端安装:

app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = "Cookies", 
      CookieName = "AuthCookieCoolApp", 

     }); 

     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
     { 
      Authority = ConfigurationManager.AppSettings["Authority"], 
      ClientId = "CoolApp", 
      RedirectUri = ConfigurationManager.AppSettings["RedirectUri"], 
      ResponseType = "id_token token", // added token here 
      SignInAsAuthenticationType = "Cookies", 
      Scope = "cool_profile openid profile", 
     } 

使用招我们看到的accessToken从Identityserver回发到redirceturi,但如何才能抓住它?我们在OpenIdConnectAuthenticationOptions上找到Notifications财产,但没有一个事件似乎适合。

红利问题:当我们获得服务器上的accesstoken(mvc)时,将它发送给浏览器的方式是什么?将其存储在服务器上,并将其发送到每个可能需要调用新api的页面上,或者在需要时从javascript请求它?

感谢您的任何指导

Larsi

回答

1

您可以从协议消息一样获得访问令牌:

Notifications = new OpenIdConnectAuthenticationNotifications 
      { 
       MessageReceived = notification => 
       { 
        var message = notification.ProtocolMessage; 
        var accesstoken = message.AccessToken; 
        return Task.FromResult(0); 
       } 
      } 
相关问题