Custom OAuth client in MVC4 / DotNetOpenAuth - missing access token secret

后端 未结 4 2109
花落未央
花落未央 2020-12-30 16:31

I\'m currently working on implementing a Dropbox OAuth client for my application. It\'s been a fairly painless process until I hit the end. Once I\'ve authorized, when I att

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 17:00

    After doing some digging, I was able to solve this by changing my constructor logic as follows:

    public DropboxClient(string consumerKey, string consumerSecret) : 
        this(consumerKey, consumerSecret, new AuthenticationOnlyCookieOAuthTokenManager())
    {
    }
    
    public DropboxClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : 
        base("dropbox", DropboxServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager))
    {
    }
    

    becomes

    public DropboxClient(string consumerKey, string consumerSecret) : 
            base("dropbox", DropboxServiceDescription, consumerKey, consumerSecret)
        {
        }
    

    Digging through the DNOA source shows that if you construct an OAuthClient (my base class) with just the consumer key and secret, it uses the InMemoryOAuthTokenManager instead of the SimpleConsumerTokenManager. I don't know why, but now my access token secret is properly appended to my signature in the authorized request and everything works. Hopefully this helps someone else. In the meantime, I'll likely clean this up for a blog post since there is zero guidance on the net (that I can find) for doing this.

    EDIT: I'm going to undo my answer since, as a colleague pointed out, this will take care of one request, but now that I'm using the in-memory manager, that will flush once I round trip fully back to the browser (I'm assuming). So I think the root issue here is that I need to get the access token secret, which I still haven't seen how to do.

提交回复
热议问题