micro/auth/auth.go

41 lines
973 B
Go
Raw Normal View History

2019-11-25 12:30:26 +03:00
// Package auth provides authentication and authorization capability
package auth
2019-11-25 12:33:30 +03:00
import (
"time"
)
2019-11-25 12:30:26 +03:00
// Auth providers authentication and authorization
type Auth interface {
2019-12-18 00:27:05 +03:00
// Generate a new auth token
Generate(string) (*Token, error)
2019-11-25 12:30:26 +03:00
// Revoke an authorization token
2019-12-18 00:27:05 +03:00
Revoke(*Token) error
// Grant access to a resource
2019-12-18 00:37:20 +03:00
Grant(*Token, *Service) error
2019-12-18 00:27:05 +03:00
// Verify a token can access a resource
2019-12-18 00:37:20 +03:00
Verify(*Token, *Service) error
2019-12-18 00:27:05 +03:00
}
2019-12-18 00:37:20 +03:00
// Service is some thing to provide access to
type Service struct {
2019-12-18 00:27:05 +03:00
// Name of the resource
Name string
2019-12-18 00:37:20 +03:00
// Endpoint is the specific endpoint
Endpoint string
2019-11-25 12:30:26 +03: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"`
}