2013-02-14 58 views
6

我必须弄清楚如何使用OAuth 2来使用Deviantart API。如何使用OAuth 2 - OAuth 2 C#示例

我得到了CLIENT_ID和client_secret部分

这里的信息,他们给

端点

你需要与我们使用OAuth 2.0认证的唯一信息是您的应用程式client_idclient_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

安慰剂呼叫

第一API调用依靠的OAuth 2.0认证是安慰剂调用。 在进行可能很长的实际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; 
} 
+0

您是否尝试过观察DNOA样本? http://www.dotnetopenauth.net/ – Mansfield 2013-02-14 13:43:11

+0

是的,但没有工作。更新了问题 – MonsterMMORPG 2013-02-14 14:04:27

回答

9

现在最简单的做法是获取Visual Studio 2013并创建一个新的ASP.NET Web应用程序选择“个人用户帐户”作为您的认证类型。在那里开箱即可使用OAuth 2实施(在App_Start \ Startup.Auth.cs中配置),您可以将其切片并适应您的需求。

+2

如果可能的话,我更喜欢基于客户端的wpf – MonsterMMORPG 2013-02-14 13:42:10

+8

MVC应用程序使用OAuth1而不是OAUth2。 – 2013-08-23 10:02:37

+1

Microsoft.Security.OWIN.OAuth使用OAuth 2: - http://www.nuget.org/packages/Microsoft.Owin.Security.OAuth/ – 2013-10-28 11:05:03