1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00
go-micro/auth/auth.go

41 lines
972 B
Go
Raw Normal View History

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