1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-24 22:26:54 +02:00

Inject Namespace into Context

This commit is contained in:
Ben Toogood
2020-04-14 09:14:07 +01:00
parent bf65dc71c7
commit d61d30ef66
5 changed files with 29 additions and 5 deletions

View File

@ -159,7 +159,7 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper {
// Inspect the token and get the account
account, err := a.Inspect(token)
if err != nil {
account = &auth.Account{}
account = &auth.Account{Namespace: a.Options().Namespace}
}
// construct the resource
@ -183,6 +183,11 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper {
return err
}
// Set the namespace in the context
if _, ok := metadata.Get(ctx, auth.NamespaceKey); !ok {
ctx = metadata.Set(ctx, auth.NamespaceKey, a.Options().Namespace)
}
// The user is authorised, allow the call
return h(ctx, req, rsp)
}