Documentation
¶
Overview ¶
`grpcauth` is an authentication and authorization gRPC server side authentication wrappers.
Please see examples for simple examples of use.
Index ¶
- func DefaultAdminGroup() string
- func DefaultAdminGroups() []string
- func DefaultSuperAdminGroup() string
- func DefaultUserGroup() string
- func Header() string
- func Scheme() string
- type API
- func (api *API) AddAdminGroups(groups ...string)
- func (api *API) AddSuperAdminGroups(groups ...string)
- func (api *API) AdminGroups() []string
- func (api *API) Authenticator(ctx context.Context) (context.Context, error)
- func (api *API) AuthenticatorWithKey(ctx context.Context, signingKey []byte) (context.Context, error)
- func (api *API) AuthorizeGroups(ctx context.Context, groups ...string) (*Payload, error)
- func (api *API) AuthorizeIds(ctx context.Context, ids ...string) (*Payload, error)
- func (api *API) GenToken(ctx context.Context, payload *Payload, expirationTime time.Time) (string, error)
- func (api *API) GenTokenFromClaims(ctx context.Context, claims *Claims, expirationTime time.Time) (string, error)
- func (api *API) GenTokenUsingKey(ctx context.Context, claims *Claims, expirationTime time.Time, ...) (string, error)
- func (api *API) GetClaims(ctx context.Context) (*Claims, error)
- func (api *API) GetClaimsFromJwt(jwt string) (*Claims, error)
- func (api *API) GetMetadataFromCtx(ctx context.Context) metadata.MD
- func (api *API) GetMetadataFromJwt(jwt string) (metadata.MD, error)
- func (api *API) GetPayload(ctx context.Context) (*Payload, error)
- func (api *API) GetSigningKey() []byte
- func (api *API) IsAdmin(group string) bool
- func (api *API) IsGroupAllowed(group string, allowedGroups ...string) bool
- func (api *API) IsSuperAdmin(group string) bool
- type Claims
- type Payload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAdminGroup ¶
func DefaultAdminGroup() string
DefaultAdminGroup is the default admin group
func DefaultAdminGroups ¶
func DefaultAdminGroups() []string
DefaultAdminGroups returns the default administrators group
func DefaultSuperAdminGroup ¶
func DefaultSuperAdminGroup() string
DefaultSuperAdminGroup is the default super admin group
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
func (*API) AddAdminGroups ¶
AddAdminGroups adds admin groups
func (*API) AddSuperAdminGroups ¶ added in v0.1.4
AddAdminGroups adds super admin groups
func (*API) AdminGroups ¶
AdminGroups retrieves Admins groups registered.
func (*API) Authenticator ¶ added in v0.0.3
Authenticator is the function that performs authentication
The passed in Context will contain the gRPC metadata.MD object (for header-based authentication) and the peer.Peer information that can contain transport-based credentials (e.g. credentials.AuthInfo).
The returned context will be propagated to handlers, allowing user changes to Context. However, please make sure that the Context returned is a child Context of the one passed in.
If error is returned, its grpc.Code() will be returned to the user as well as the verbatim message. Please make sure you use codes.Unauthenticated (lacking auth) and codes.PermissionDenied
func (*API) AuthenticatorWithKey ¶ added in v0.0.3
func (api *API) AuthenticatorWithKey(ctx context.Context, signingKey []byte) (context.Context, error)
AuthenticatorWithKey works like Authenticator but allow users to pass in custome key for decoding jwt data
func (*API) AuthorizeGroups ¶ added in v0.0.3
AuthorizeGroups checks whether the claims Group in the context metadata.MD Authorization JWT is a member the allowed groups set
If it's a member, Authorization will succeed, otherwise it will fail with codes.PermissionDenied.
The function will attempt to extract JWT token from gRPC metadata.MD Authorization key from the Context.
If getting metadata.MD object from Context fails i.e due to missing metadata.MD object OR missing Authorization key in the metadata.MD object, the function will fail with codes.Unauthenticated
It is expected that before calling this method, Authentication ought to have happened.
func (*API) AuthorizeIds ¶ added in v0.0.3
AuthorizeIds checks whether the claims Id in the context metadata.MD Authorization JWT is a member the allowed Ids set
If it's a member, Authorization will succeed, otherwise it will fail with codes.PermissionDenied.
The function will attempt to extract JWT token from gRPC metadata.MD Authorization key from the Context.
If getting metadata.MD object from Context fails i.e due to missing metadata.MD object OR missing Authorization key in the metadata.MD object, the function will fail with codes.Unauthenticated
It is expected that before calling this method, Authentication ought to have happened.
func (*API) GenToken ¶
func (api *API) GenToken(ctx context.Context, payload *Payload, expirationTime time.Time) (string, error)
GenToken generates JWT token with given payload that expire after expirationTime elapses.
It uses the receivers SigningMethod and SigningKey to sign the token.
func (*API) GenTokenFromClaims ¶
func (api *API) GenTokenFromClaims(ctx context.Context, claims *Claims, expirationTime time.Time) (string, error)
GenTokenFromClaims generates JWT token with given claims that expire after expirationTime elapses.
It uses the receivers SigningMethod and default secret to sign the token.
func (*API) GenTokenUsingKey ¶
func (api *API) GenTokenUsingKey(ctx context.Context, claims *Claims, expirationTime time.Time, signingKey []byte) (string, error)
GenTokenUsingKey generates JWT token with given payload that expire after expirationTime elapses.
It uses the provided signingKey and the receiver SigningMethod to sign the token.
func (*API) GetClaimsFromJwt ¶
GetClaimsFromJwt retrives claims by parsing the jwt string.
It uses the reciever SigningKey during parsing.
func (*API) GetMetadataFromCtx ¶
GetMetadataFromCtx retrieves metadata.MD object from Context
func (*API) GetMetadataFromJwt ¶
GetMetadataFromJwt creates a metadata.MD object from jwt string.
func (*API) GetPayload ¶ added in v0.0.3
GetPayload retrives Payload from Claims in claimsKey of the Context
func (*API) GetSigningKey ¶ added in v0.0.3
GetSigningKey retrieves the signing key registered for the auth instance
func (*API) IsGroupAllowed ¶ added in v0.1.4
IsGroupAllowed checks whether group is in the list of allowed groups.
func (*API) IsSuperAdmin ¶ added in v0.1.4
IsAdmin checks whether the provided group belongs to the Super Admin Groups.
type Claims ¶
type Claims struct {
*Payload
jwt.StandardClaims
}
Claims contains JWT claims information