Jeff-Lewis / oauth-dot-net

Automatically exported from code.google.com/p/oauth-dot-net
0 stars 0 forks source link

NullReferenceException in OAuthRequestToken.cs #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This method in OAuthRequestToken.cs throws a NullReferenceException when 
the AuthenticatedUser property is null, which is a valid state for a 
request token.

I am experiencing this error when the RequestTokenHandler process my 
callback URI.

public override int GetHashCode()
        {
            return this.Token.GetHashCode() ^ this.Secret.GetHashCode() ^ 
this.Status.GetHashCode()
                ^ this.ConsumerKey.GetHashCode() ^ 
this.AssociatedParameters.GetHashCode()
                ^ this.AuthenticatedUser.GetHashCode() ^ 
this.Roles.GetHashCode();
        }

Original issue reported on code.google.com by billyz...@yahoo.com on 3 Aug 2009 at 6:18

GoogleCodeExporter commented 9 years ago
The Equals method has the same problem. These two methods get implicitly 
evaluated 
by the InMemoryCallbackStore which uses a dictionary for storage.

Original comment by billyz...@yahoo.com on 3 Aug 2009 at 6:27

GoogleCodeExporter commented 9 years ago
Another related issuein the Equals method:

public override bool Equals(object obj)
{
    if (obj == null)
        return false;

    if (obj is OAuthRequestToken) <-- is this correct?? this always returns false!
        return false;

    return this.Equals((IRequestToken)obj);
}

Original comment by billyz...@yahoo.com on 3 Aug 2009 at 6:56

GoogleCodeExporter commented 9 years ago
Ok, so a little more digging. Basically, checking the Keys property of a 
dictionary 
for a request token (e.g. what InMemoryCallbackStore does) does not currently 
work 
at all, even if the tokens are the exact same references!

It has to do with all three of these methods below. Note that I had to comment 
out 
the bulk of these methods as a workaround to get ContainsKey working. So these 
definitely need further review/testing.

        public override bool Equals(object obj)
        {
            return Equals(obj as IRequestToken);

            /* commented out by Will
            if (obj == null)
                return false;

            if (obj is OAuthRequestToken)
                return false;

            return this.Equals((IRequestToken)obj);
            */
        }

        public bool Equals(IRequestToken other)
        {
            if (other == null)
                return false;

            return base.Equals(other);

            /* commented out by Will
            return this.Token.Equals(other.Token)
                && this.Secret.Equals(other.Secret)
                && this.Status == other.Status
                && this.ConsumerKey.Equals(other.ConsumerKey)
                && this.AssociatedParameters.Equals(other.AssociatedParameters)
                && this.AuthenticatedUser.Equals(other.AuthenticatedUser)
                && Array.Equals(this.Roles, other.Roles);
            */
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();

            /* commented out by Will
            return this.Token.GetHashCode() ^ this.Secret.GetHashCode() ^ 
this.Status.GetHashCode()
                ^ this.ConsumerKey.GetHashCode() ^ 
this.AssociatedParameters.GetHashCode()
                ^ this.AuthenticatedUser.GetHashCode() ^ this.Roles.GetHashCode();
            */
        }

Original comment by billyz...@yahoo.com on 3 Aug 2009 at 7:13

GoogleCodeExporter commented 9 years ago
Fix implemented into trunk.

Original comment by chris.s....@gmail.com on 4 Aug 2009 at 3:32