DotNetOpenAuth OAuth2 for Basecamp API

情到浓时终转凉″ 提交于 2019-12-07 16:59:34

问题


I'm having some difficulties getting the OAuth2 working for the Basecamp API with DotNetOpenAuth, here's what I have so far, this is a ASP.NET MVC 4 web app.

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;
}

The is the error I get from Basecamp:

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

I've tried to search and look around, and could not found much interesting. Any help / pointer would be appreciated.

Thanks


回答1:


Change this:

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

to this:

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

Note: i added type=web_server to the end of the uri.

Take from these official docs.



来源:https://stackoverflow.com/questions/17455074/dotnetopenauth-oauth2-for-basecamp-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!