如何使用OAuth 2-OAuth 2 C#示例 [英] How to use OAuth 2 - OAuth 2 C# example
问题描述
我必须弄清楚如何使用OAuth 2才能使用Deviantart api。
I have to figure out how to use OAuth 2 in order to use Deviantart api.
我有client_id和client_secret部分
I got the client_id and client_secret part
此处提供的信息
端点
您需要认证的唯一信息使用OAuth 2.0与我们一起使用的是您应用的 client_id
和 client_secret
值,以及以下所示的端点。
The only information you need to authenticate with us using OAuth 2.0 are the client_id
and client_secret
values for your app, as well as the endpoint shown below.
OAuth 2.0草案10:
OAuth 2.0 draft 10:
https://www.deviantart.com/oauth2/draft10/authorize
https://www.deviantart.com/oauth2/draft10/token
OAuth 2.0草案15:
OAuth 2.0 draft 15:
https://www.deviantart。 com / oauth2 / draft15 / authorize
https://www.deviantart.com/oauth2/draft15/token
安慰剂呼叫
第一个依赖OAuth 2.0身份验证的API调用是安慰剂调用。
在进行可能很长的真实API调用(例如文件上传)之前,检查访问令牌是否仍然有效。
您可以使用以下端点之一(必须提供访问令牌)来调用它:
The first API call relying on OAuth 2.0 authentication is the placebo call. It's useful for checking that an access token is still valid before making a real API call that might be long, like a file upload. You call it with one of the following endpoints (an access token must be provided):
https://www.deviantart.com/api/draft10/placebo
https://www.deviantart.com/api/draft15/placebo
您需要使用与您已获得令牌的OAuth 2.0草案相对应的端点。
You need to use the endpoint that corresponds to the OAuth 2.0 draft you've obtained your token with.
它始终返回以下JSON: {状态: 成功}
It always returns the following JSON: {status: "success"}
我已经在网上搜索并找到了这个很棒的库。
I have searched the web and found this awesome library.
DotNetOpenAuth v4.0.1
DotNetOpenAuth v4.0.1
http://www.dotnetopenauth.net/
已将其添加为参考,但不知道下一步该怎么做。就如何使用DotNetOpenAuth使用OAuth 2
Added it as reference but have no idea what to do next. Even a very small example would be really useful about how to use OAuth 2
using DotNetOpenAuth;
using DotNetOpenAuth.OAuth2;
此处是deviantart提供信息的页面
Here the page where deviantart gives the information
http://www.deviantart.com/developers/oauth2
在这里好了,到目前为止,我没有得到任何帮助
Ok here what i got so far but not working
public static WebServerClient CreateClient() {
var desc = GetAuthServerDescription();
var client = new WebServerClient(desc, clientIdentifier: "myid");
client.ClientCredentialApplicator = ClientCredentialApplicator.PostParameter("mysecret");
return client;
}
public static AuthorizationServerDescription GetAuthServerDescription() {
var authServerDescription = new AuthorizationServerDescription();
authServerDescription.AuthorizationEndpoint = new Uri(@"https://www.deviantart.com/oauth2/draft15/authorize");
authServerDescription.TokenEndpoint = new Uri(@"https://www.deviantart.com/oauth2/draft15/token");
authServerDescription.ProtocolVersion = ProtocolVersion.V20;
return authServerDescription;
}
推荐答案
现在最简单的方法是获取Visual Studio 2013,并选择个人用户帐户作为身份验证类型,创建一个新的ASP.NET Web应用程序。有一个可用的OAuth 2有效实现(在App_Start\Startup.Auth.cs中配置),您可以对其进行拆分,然后根据需要进行调整。
Easiest thing to do now is get Visual Studio 2013 and create a new ASP.NET Web Application choosing "Individual User Accounts" as your authentication type. There's a working OAuth 2 implementation out of the box in there (configured at App_Start\Startup.Auth.cs) which you can slice out and then adapt to your needs.
这篇关于如何使用OAuth 2-OAuth 2 C#示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!