5

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

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."

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

谢谢

4

1 回答 1

7

改变这个:

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 的末尾。

这些官方文档中获取。

于 2013-07-05T12:05:58.943 回答