Auth Improvements (#1195)
* Exclude Stats & Trace from Auth * Update Excluded Endpoints Format * Tweak Implementation
This commit is contained in:
parent
ea70711dd3
commit
e080ecb43a
@ -257,7 +257,7 @@ var (
|
|||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "auth_exclude",
|
Name: "auth_exclude",
|
||||||
EnvVars: []string{"MICRO_AUTH_EXCLUDE"},
|
EnvVars: []string{"MICRO_AUTH_EXCLUDE"},
|
||||||
Usage: "Comma-separated list of endpoints excluded from authentication",
|
Usage: "Comma-separated list of endpoints excluded from authentication, e.g. Users.ListUsers",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,18 +145,14 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper {
|
|||||||
// get the auth.Auth interface
|
// get the auth.Auth interface
|
||||||
a := fn()
|
a := fn()
|
||||||
|
|
||||||
// Extract endpoint and remove service name prefix
|
// Check for debug endpoints which should be excluded from auth
|
||||||
// (e.g. Platform.ListServices => ListServices)
|
if strings.HasPrefix(req.Endpoint(), "Debug.") {
|
||||||
var endpoint string
|
return h(ctx, req, rsp)
|
||||||
if ec := strings.Split(req.Endpoint(), "."); len(ec) == 2 {
|
|
||||||
endpoint = ec[1]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for endpoints excluded from auth. If the endpoint
|
// Exclude any user excluded endpoints
|
||||||
// matches, execute the handler and return
|
for _, e := range a.Options().Excludes {
|
||||||
excludes := append(a.Options().Excludes, "Stats", "Trace")
|
if e == req.Endpoint() {
|
||||||
for _, e := range excludes {
|
|
||||||
if e == endpoint {
|
|
||||||
return h(ctx, req, rsp)
|
return h(ctx, req, rsp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user