mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
Adding peer registration support to JWT (#305)
The management will validate the JWT as it does in the API and will register the Peer to the user's account. New fields were added to grpc messages in management and client daemon and its clients were updated Peer has one new field, UserID, that will hold the id of the user that registered it JWT middleware CheckJWT got a splitter and renamed to support validation for non HTTP requests Added test for adding new Peer with UserID Lots of tests update because of a new field
This commit is contained in:
@@ -35,20 +35,25 @@ func NewClaimsExtractor(e ExtractClaims) *ClaimsExtractor {
|
||||
}
|
||||
|
||||
// ExtractClaimsFromRequestContext extracts claims from the request context previously filled by the JWT token (after auth)
|
||||
func ExtractClaimsFromRequestContext(r *http.Request, authAudiance string) AuthorizationClaims {
|
||||
func ExtractClaimsFromRequestContext(r *http.Request, authAudience string) AuthorizationClaims {
|
||||
token := r.Context().Value(TokenUserProperty).(*jwt.Token)
|
||||
return ExtractClaimsWithToken(token, authAudience)
|
||||
}
|
||||
|
||||
// ExtractClaimsWithToken extracts claims from the token (after auth)
|
||||
func ExtractClaimsWithToken(token *jwt.Token, authAudience string) AuthorizationClaims {
|
||||
claims := token.Claims.(jwt.MapClaims)
|
||||
jwtClaims := AuthorizationClaims{}
|
||||
jwtClaims.UserId = claims[UserIDClaim].(string)
|
||||
accountIdClaim, ok := claims[authAudiance+AccountIDSuffix]
|
||||
accountIdClaim, ok := claims[authAudience+AccountIDSuffix]
|
||||
if ok {
|
||||
jwtClaims.AccountId = accountIdClaim.(string)
|
||||
}
|
||||
domainClaim, ok := claims[authAudiance+DomainIDSuffix]
|
||||
domainClaim, ok := claims[authAudience+DomainIDSuffix]
|
||||
if ok {
|
||||
jwtClaims.Domain = domainClaim.(string)
|
||||
}
|
||||
domainCategoryClaim, ok := claims[authAudiance+DomainCategorySuffix]
|
||||
domainCategoryClaim, ok := claims[authAudience+DomainCategorySuffix]
|
||||
if ok {
|
||||
jwtClaims.DomainCategory = domainCategoryClaim.(string)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user