micro/auth/auth.go

41 lines
972 B
Go
Raw Normal View History

2019-11-25 09:30:26 +00:00
// Package auth provides authentication and authorization capability
package auth
2019-11-25 09:33:30 +00:00
import (
"time"
)
2019-11-25 09:30:26 +00:00
// Auth providers authentication and authorization
type Auth interface {
2019-12-17 21:27:05 +00:00
// Generate a new auth token
Generate(string) (*Token, error)
2019-11-25 09:30:26 +00:00
// Revoke an authorization token
2019-12-17 21:27:05 +00:00
Revoke(*Token) error
// Grant access to a resource
2019-12-17 21:37:20 +00:00
Grant(*Token, *Service) error
2019-12-17 21:27:05 +00:00
// Verify a token can access a resource
2019-12-17 21:37:20 +00:00
Verify(*Token, *Service) error
2019-12-17 21:27:05 +00:00
}
2019-12-17 21:37:20 +00:00
// Service is some thing to provide access to
type Service struct {
2019-12-17 21:27:05 +00:00
// Name of the resource
Name string
2019-12-18 15:06:02 +00:00
// Endpoint is the specific endpoint
2019-12-17 21:37:20 +00:00
Endpoint string
2019-11-25 09:30:26 +00:00
}
// Token providers by an auth provider
type Token struct {
// Unique token id
Id string `json: "id"`
// Time of token creation
Created time.Time `json:"created"`
// Time of token expiry
Expiry time.Time `json:"expiry"`
// Roles associated with the token
Roles []string `json:"roles"`
// Any other associated metadata
Metadata map[string]string `json:"metadata"`
}