用于Basecamp API的DotNetOpenAuth OAuth2

时间:2013-07-03 17:58:07

标签: c# asp.net-mvc dotnetopenauth basecamp

我在使用DotNetOpenAuth使用OAuth2为Basecamp API工作时遇到了一些困难,这是我到目前为止所使用的,这是一个ASP.NET MVC 4网络应用程序。

public ActionResult Basecamp()
{
    var server = new DotNetOpenAuth.OAuth2.AuthorizationServerDescription();
    server.AuthorizationEndpoint = new Uri("https://launchpad.37signals.com/authorization/new");
    server.TokenEndpoint = new Uri("https://launchpad.37signals.com/authorization/token");

    var client = new DotNetOpenAuth.OAuth2.WebServerClient(
        server, "my-basecamp-id", "my-basecamp-secret");

    client.RequestUserAuthorization(returnTo: new Uri("http://localhost:55321/settings/basecampauth"));
    Response.End();

    return null;
}

[HttpPost]
public ActionResult BasecampAuth()
{
    var server = new DotNetOpenAuth.OAuth2.AuthorizationServerDescription();
    server.AuthorizationEndpoint = new Uri("https://launchpad.37signals.com/authorization/new");
    server.TokenEndpoint = new Uri("https://launchpad.37signals.com/authorization/token");


    var client = new DotNetOpenAuth.OAuth2.WebServerClient(
        server, "my-basecamp-id", "my-basecamp-secret");

    var state = client.ProcessUserAuthorization(Request);
    Response.Write(state.AccessToken);
    Response.End();
    return null;
}

这是我从Basecamp得到的错误:

--- 
:error: "Unsupported type: nil. We support user_agent and web_server."

我试图搜索并环顾四周,并没有找到太多有趣的东西。任何帮助/指针都将不胜感激。

由于

1 个答案:

答案 0 :(得分:5)

改变这个:

server.AuthorizationEndpoint = new Uri("https://launchpad.37signals.com/authorization/new");

到此:

server.AuthorizationEndpoint = new Uri("https://launchpad.37signals.com/authorization/new?type=web_server");

注意:我将type=web_server添加到了uri的末尾。

these official docs获取。