jhoerr / box-csharp-sdk-v2

A C# client for the Box API (v2).
http://developers.box.com/docs/
11 stars 15 forks source link

Using Legacy Auth Solution Throws Error in VS 2010 #7

Closed mascon closed 11 years ago

mascon commented 11 years ago

When you use the following code

Dim BoxClient As New BoxManager(BoxAccount.API_Key, BoxAccount.Auth_Token)

It results in this error message within VS 2010

.ctor' is ambiguous because multiple kinds of members with this name exist in class BoxApi.V2.BoxManager'.

We are not ready to port to OAuth2 yet and that is planned in the future. No date is set by BOX on the depreciation of this old method at this time so a fix in the code would be appreciated.

jhoerr commented 11 years ago

Arg. I think the least invasive way to resolve this will be by making the auth token and proxy required arguments. Both can be null, though.

jhoerr commented 11 years ago

Resolved in 324b5f1dc5. Let me know if the fix is overly burdensome.

mascon commented 11 years ago

Fixed, however does not mention now that this is obsolete.

mascon commented 11 years ago

Sorry to say it appeared fixed but crashes when I run the code.

    Dim BoxClient As New BoxManager(BoxAccount.API_Key, BoxAccount.Auth_Token)

    Dim BoxUsers = BoxClient.GetUsers("", 1, 0)

First line works fine second line dies here in BoxRestClient.cs

    public T ExecuteAndDeserialize<T>(IRestRequest request) where T : class, new()
    {
        IRestResponse<T> restResponse = base.Execute<T>(request);
        return restResponse.Data;
    }
mascon commented 11 years ago

Additional information

It calls the wrong constructor, this is the one the code hits hence fails.

    public BoxManager(string clientId, string clientSecret, string accessToken = null, string refreshToken = null, IWebProxy proxy = null) : this(proxy)
    {
        _clientId = clientId;
        _clientSecret = clientSecret;
        ConfigureRestClient(accessToken, refreshToken);
    }
jhoerr commented 11 years ago

Simon -- sorry this is still presenting problems. I think the problem is that

Dim BoxClient As New BoxManager(BoxAccount.API_Key, BoxAccount.Auth_Token)

should be

Dim BoxClient As New BoxManager(BoxAccount.API_Key, BoxAccount.Auth_Token, null)

That this continues to be so brittle tells me that I need to find another solution to the problem. I think I might have the constructor take an IBoxAuthenticator instead of the various combinations of strings. That will at the very least be a little more intention revealing.

mascon commented 11 years ago

Hi john

Tried that no difference

Cheers

Simon

Sent from my BlackBerry® wireless device

-----Original Message----- From: John Hoerr notifications@github.com Date: Fri, 04 Jan 2013 07:31:24 To: jhoerr/box-csharp-sdk-v2box-csharp-sdk-v2@noreply.github.com Reply-To: jhoerr/box-csharp-sdk-v2 reply@reply.github.com Cc: masconimom@andimgone.com Subject: Re: [box-csharp-sdk-v2] Using Legacy Auth Solution Throws Error in VS 2010 (#7)

Simon -- sorry this is still presenting problems. I think the problem is that

Dim BoxClient As New BoxManager(BoxAccount.API_Key, BoxAccount.Auth_Token)

should be

Dim BoxClient As New BoxManager(BoxAccount.API_Key, BoxAccount.Auth_Token, null)

That this continues to be so brittle tells me that I need to find another solution to the problem. I think I might have the constructor take an IBoxAuthenticator instead of the various combinations of strings. That will at the very least be a little more intention revealing.


Reply to this email directly or view it on GitHub: https://github.com/jhoerr/box-csharp-sdk-v2/issues/7#issuecomment-11886682

jhoerr commented 11 years ago

Ok -- I'm working on something better.

mascon commented 11 years ago

Any update on this one?

jhoerr commented 11 years ago

No update. The weekend got away from me.

jhoerr commented 11 years ago

Fixed in abd4796d1a2e843e8a407f389a98cc816a2cec98.

I modified the BoxManager constructors to take one of the v1/v2 IRequestAuthenticators instead of all the credentials. Got rid of the old v1 constructor and obsoleted the existing v2 one. Will remove it after a while.

mascon commented 11 years ago

Using the following constructor requires me now to add the restsharp.dll as a reference to my project

Dim BoxClient As New BoxManager(New LegacyRequestAuthenticator(BoxAccount.API_Key, BoxAccount.Auth_Token))

Should that be the case?

jhoerr commented 11 years ago

That's certainly not ideal. I changed them again in fc32e9b83c08280d76e4e73280f89d818606fad4 to just take the required string credentials (v2: access token; v1: api key and auth token.) Those are no longer optional, and should resolve the ambiguity without requiring the additional reference.

mascon commented 11 years ago

This is functioning for sure for the V1 now without issue. I have yet to complete the V2 code and for now I will leave focus on the update of the scripts and not getting OAuth functioning.

I do however have a question. The scripts I have can run for an hour or two. There is one object created. Does the Code automatically refresh the token if the object is still active?

jhoerr commented 11 years ago

No, it does not automatically refresh the token. The reason for this is that you'll want to know when a refresh is required so that you can fetch and persist the new access/refresh token pair. (It would not be good for the BoxManager to be the only thing that knows the new token values.)

I think a good pattern would be to look for exceptions with an Unauthorized status (401), refresh/persist the tokens, create a new client, and retry the operation.

On Jan 10, 2013, at 5:35 PM, mascon notifications@github.com wrote:

This is functioning for sure for the V1 now without issue. I have yet to complete the V2 code and for now I will leave focus on the update of the scripts and not getting OAuth functioning.

I do however have a question. The scripts I have can run for an hour or two. There is one object created. Does the Code automatically refresh the token if the object is still active?

— Reply to this email directly or view it on GitHub.

mascon commented 11 years ago

I was hoping to just get this at the end of the operation from the boxmanager

Also for me since it is always long running I could just handle this action first thing as the app started.

App Start

Create Refresh token

Store values

Create BoxManager instance

Long running program 2-3 hours

Close app

24 hours later same again. As the refresh token lasts 14 days this would be prefect.

jhoerr commented 11 years ago

Yeah, I hear you. As an 'eater of my own dog good' this would surely be convenient. The concern that I have is that you now have to assume that your tokens have been surreptitiously changed any and every time you use a BoxManager. This creates a persistence burden that, to me, feels quite brittle. (I create and dispose of BoxManagers much more frequently than you, which probably has something to do with it.)

mascon commented 11 years ago

I also see other issue too, I wander how box will handle the "Work as this user" feature too in the new API V2.

For now as you know I am going to use V1 Auth so unless you see it as a good idea and something to implement I will not moan and groan any longer LOL