我需要弄清楚如何使用OAuth 2来使用Deviantart API。
已经获取了client_id
和client_secret
部分。
下面是提供的信息:
终端点
您只需要使用OAuth 2.0进行身份验证的信息是应用程序的client_id
和client_secret
值,以及下面显示的终端点。
OAuth 2.0草案10:
https://www.deviantart.com/oauth2/draft10/authorize https://www.deviantart.com/oauth2/draft10/token
OAuth 2.0草案15:
https://www.deviantart.com/oauth2/draft15/authorize https://www.deviantart.com/oauth2/draft15/token
Placebo调用
第一个依赖OAuth 2.0身份验证的API调用是Placebo调用。 它很有用,可以在执行可能很长的真实API调用(如文件上传)之前检查访问令牌是否仍然有效。 您可以使用以下其中一个终端点进行调用(必须提供访问令牌):
https://www.deviantart.com/api/draft10/placebo https://www.deviantart.com/api/draft15/placebo
您需要使用与您获取令牌的OAuth 2.0草案对应的终端点。
它始终返回以下JSON:{status: "success"}
我在网上搜索并找到了这个很棒的库。
DotNetOpenAuth v4.0.1
http://www.dotnetopenauth.net/
将其添加为引用,但不知道接下来该怎么办。即使有一个非常小的示例也将非常有用,说明如何使用OAuth 2。
using DotNetOpenAuth;
using DotNetOpenAuth.OAuth2;
这里是deviantart提供信息的页面
http://www.deviantart.com/developers/oauth2
这是我目前拥有的,但还没有生效。
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;
}