使用asp.net获取soundcloud Oauth2令牌(Get soundcloud Oauth2 token with asp.net)

编程入门 行业动态 更新时间:2024-10-09 15:17:26
使用asp.net获取soundcloud Oauth2令牌(Get soundcloud Oauth2 token with asp.net)

我已成功设法授权我的ASP.NET应用程序/登录第三方服务(在本例中为Soundcloud)。 我想要使​​用的API需要在登录过程中提供的授权令牌。 我在哪里可以获得令牌?

I have successfully managed to authorise my ASP.NET application/login against a 3rd party service (in this case Soundcloud). The API I want to use requires the authorisation token that was provided during the login process. Where can I get the token?

最满意答案

我找到了答案以防其他人想知道,通过使用选项中的Provider属性可以获得令牌。 在这种情况下,我使用令牌设置了一个声明,然后我可以在SignInManager.AuthenticationManager.GetExternalLoginInfo()的claim属性中访问它。

app.UseSoundCloudAuthentication(new SoundCloudAuthenticationOptions { ClientId = "CLIENT_ID", ClientSecret = "CLIENT_SECRET", Provider = new Owin.Security.Providers.SoundCloud.Provider.SoundCloudAuthenticationProvider { OnAuthenticated = async context => { context.Identity.AddClaim(new Claim("AccessToken", context.AccessToken)); await Task.Yield(); } } }); var accessToken = info.ExternalIdentity.Claims.Single(x => x.Type == "AccessToken").Value;

I found the answer in case anyone else wants to know, the token is available by using the Provider property in the options. In this case, I set a claim with the token, which I can then access in the claims property of SignInManager.AuthenticationManager.GetExternalLoginInfo()

app.UseSoundCloudAuthentication(new SoundCloudAuthenticationOptions { ClientId = "CLIENT_ID", ClientSecret = "CLIENT_SECRET", Provider = new Owin.Security.Providers.SoundCloud.Provider.SoundCloudAuthenticationProvider { OnAuthenticated = async context => { context.Identity.AddClaim(new Claim("AccessToken", context.AccessToken)); await Task.Yield(); } } }); var accessToken = info.ExternalIdentity.Claims.Single(x => x.Type == "AccessToken").Value;

更多推荐

本文发布于:2023-07-30 14:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338775.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   net   asp   soundcloud   token

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!