简体   繁体   English

如何在第三方ASP.NET Web API客户端中使用Oauth生成的令牌?

[英]How to use an Oauth Generated Token in a 3rd party asp.net web API client?

I am new to asp.net web API. 我是ASP.NET Web API的新手。

I am planning to use Token based authentication for a simple web API I am creating in C#. 我打算将基于令牌的身份验证用于在C#中创建的简单Web API。

I have created the API and used the following code to create the token 我已经创建了API,并使用以下代码创建了令牌

OAuthOptions = new OAuthAuthorizationServerOptions
{
   TokenEndpointPath = new PathString("/Token"),
   Provider = new SimpleAuthorizationServerProvider(),
   AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
   AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
   // In production mode set AllowInsecureHttp = false
   AllowInsecureHttp = true
};

I used postman tool to test the api by copying the token generated by the above code and by prefixing the keyword Bearer to it. 我使用邮递员工具通过复制上述代码生成的令牌并在其前面加上关键字Bearer来测试api。

Everything works fine. 一切正常。

However, I have the following questions, for which I couldn't find a proper answer. 但是,我有以下问题,无法找到正确的答案。

  1. How a third party client will know about the generated token? 第三方客户如何知道生成的令牌?
  2. Since the token expires in 14 days, how the client will know about the updated token? 由于令牌在14天后到期,因此客户将如何知道更新的令牌?

You pass them back the token from the login and they use it as the bearer token. 您将它们从登录名传递回令牌,他们将其用作承载令牌。

You can also give them a refresh token that acts like a username/password, client checks of they get an auth failure and then they'll use the refresh token to get a new bearer token. 您还可以给他们一个刷新令牌,其作用类似于用户名/密码,客户端检查它们是否获得身份验证失败,然后他们将使用刷新令牌来获得新的承载令牌。

Really depends on your app. 真的取决于您的应用程序。 If it's a mobile app, you might just set it to never expire to make things easier (if there is no risk). 如果是移动应用程序,则可以将其设置为永不过期,以使事情变得更容易(如果没有风险)。 Websites you can ask them to log in again after 14 days, or use a refresh token. 您可以要求他们在14天后再次登录的网站,或使用刷新令牌。 Lots of options 很多选择

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET 核心 Web API - 如何使用第 3 方 API 基于条件 - ASP.NET Core Web API - How to Consume 3rd party API Based on Condition ASP.NET Core Web API - 如何使用 HttpClient 使用 3rd 方 API - ASP.NET Core Web API - How to Consume 3rd party API using HttpClient 如何在asp.net core web api中实现JWT Refresh Tokens(没有第三方)? - How to implement JWT Refresh Tokens in asp.net core web api (no 3rd party)? 我如何验证第三方用户访问我的Web API asp.net? - how do i authenticate 3rd party user to access my web API asp.net? 如何在不等待 ASP.NET API 中的响应的情况下处理多个 3rd 方 API - How to process multiple 3rd party APIs without waiting for their response in ASP.NET API 如何在ASP.NET Web API中保存OAuth访问令牌 - How to save OAuth Access Token in ASP.NET Web API 无法在ASP.NET应用程序中使用第三方DLL,但可以在Windows Forms .NET应用程序中使用 - Unable to use a 3rd party DLL in an ASP.NET application, but works from a Windows Forms .NET application 从ASP.Net MVC控制器中的第三方API返回JSON字符串 - Returning JSON string from 3rd party API in ASP.Net MVC controller 在ASP.NET MVC中管理对第三方应用程序的共享API调用的最佳场所 - Best Place to manage shared API calls to 3rd party application inside my asp.net mvc asp.net将第3方dll部署到bin文件夹 - asp.net deploy 3rd party dlls to bin folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM