Skip to content

Comments

auth/jwt: MapClaims: passing#568

Merged
peterbourgon merged 3 commits intogo-kit:issue-562from
litriv:issue-562
Jul 13, 2017
Merged

auth/jwt: MapClaims: passing#568
peterbourgon merged 3 commits intogo-kit:issue-562from
litriv:issue-562

Conversation

@litriv
Copy link
Contributor

@litriv litriv commented Jul 11, 2017

add claimsFactory type
make NewParser take a claimsFactory instead of an instance of jwt.Claims
use claimsFactory to create a jwt.Claims to pass in to jwt.ParseWithClaims
update NewParser calls in tests to take a claimsFactory instead of a jwt.Claims instance

add claimsFactory type
make NewParser take a claimsFactory instead of an instance of jwt.Claims
use claimsFactory to create a jwt.Claims to pass in to jwt.ParseWithClaims
update NewParser calls in tests to take a claimsFactory instead of a jwt.Claims instance
}
}

type claimsFactory func() jwt.Claims
Copy link
Member

@peterbourgon peterbourgon Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be exported, ClaimsFactory.

}

parser := NewParser(keys, method, jwt.MapClaims{})(e)
parser := NewParser(keys, method, func() jwt.Claims { return jwt.MapClaims{} })(e)
Copy link
Member

@peterbourgon peterbourgon Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This anonymous func should be provided as a top-level function in the package, e.g.

// MapClaimsFactory is a ClaimsFactory that returns 
// an empty jwt.MapClaims.
func MapClaimsFactory() jwt.Claims {
    return jwt.MapClaims{}
}


// Test for malformed token error response
parser = NewParser(keys, method, &jwt.StandardClaims{})(e)
parser = NewParser(keys, method, func() jwt.Claims { return &jwt.StandardClaims{} })(e)
Copy link
Member

@peterbourgon peterbourgon Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this anonymous func should be provided as a top-level function in the package, e.g.

// StandardClaimsFactory is a ClaimsFactory that returns 
// an empty jwt.StandardClaims.
func StandardClaimsFactory() jwt.Claims {
    return &jwt.StandardClaims{}
}

@litriv
Copy link
Contributor Author

litriv commented Jul 12, 2017

thanks @peterbourgon - good points, all fixed now. sorry for the sloppiness - a bit pressed for time. let me know of other changes and i'll happily make them :)

}
}

type ClaimsFactory func() jwt.Claims
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops yeah! done now :)

@peterbourgon peterbourgon merged commit b42a850 into go-kit:issue-562 Jul 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants