-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added: support for audiences as regexp
- Loading branch information
Showing
4 changed files
with
56 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
package jwt | ||
|
||
import "errors" | ||
import ( | ||
"errors" | ||
"net/url" | ||
"regexp" | ||
) | ||
|
||
// Config specifies the parameters for which to perform validation of JWT | ||
// tokens in requests against. | ||
type Config struct { | ||
PublicKeys map[string]PublicKey | ||
Audiences []*Audience | ||
PublicKeys map[string]PublicKey | ||
MatchAudiences *regexp.Regexp | ||
} | ||
|
||
// Validate validates the Configuration. | ||
func (cfg *Config) Validate() error { | ||
if len(cfg.Audiences) == 0 { | ||
return errors.New("No audiences defined") | ||
} | ||
for _, aud := range cfg.Audiences { | ||
if err := aud.Validate(); err != nil { | ||
return err | ||
} | ||
if cfg.MatchAudiences == nil { | ||
return errors.New("No audiences to match defined") | ||
} | ||
if len(cfg.PublicKeys) == 0 { | ||
return errors.New("No public keys defined") | ||
} | ||
return nil | ||
} | ||
|
||
func (cfg *Config) containsAudience(aud *Audience) bool { | ||
for _, aud2 := range cfg.Audiences { | ||
if *aud == *aud2 { | ||
return true | ||
} | ||
} | ||
return false | ||
func (cfg *Config) matchesAudience(aud *Audience) bool { | ||
return cfg.MatchAudiences.MatchString((*url.URL)(aud).String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters