简体   繁体   English

ASP .NET MVC-如何在将来的REST调用中使用OAuth登录中的令牌

[英]ASP .NET MVC - How to use token from OAuth Sign In with future REST calls

I have an ASP .NET MVC application (default template). 我有一个ASP .NET MVC应用程序(默认模板)。

I have added a Nuget package for OAuth support for an external provider. 我已经为外部提供商的OAuth支持添加了一个Nuget包。

I have successfully logged in with the external provider, however I now need to use the token that they provide to make REST calls with another API I am using. 我已经成功使用外部提供程序登录,但是现在我需要使用它们提供的令牌来使用我正在使用的另一个API进行REST调用。

How do I get the token the external provider has given? 如何获得外部提供商提供的令牌?

You should refer to the external provider's docs to see how you can get the token. 您应该参考外部提供商的文档,以了解如何获取令牌。 For the ASP.NET's own identity you call %appurl%/token and then store it somewhere like in your session and then send it in your authorization header as described here. 对于ASP.NET自己的身份,可以调用%appurl%/ token,然后将其存储在会话中的某个位置,然后将其发送到授权标头中,如此处所述。 http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api

For most providers it should work because ASP.NET itself works with the token of let's say facebook and generates a token for you itself so you always use yourapplication/token to get the token. 对于大多数提供程序来说,它应该可以工作,因为ASP.NET本身可以与Facebook令牌一起工作,并为您自己生成令牌,因此您始终使用应用程序/令牌来获取令牌。

See this question MVC 5 Web API with Facebook access token to RegisterExternal without need of Cookie 看到此问题, 具有Facebook访问令牌的MVC 5 Web API可以注册到RegisterExternal,而无需Cookie

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM