2020-03-07 11:06:57 +00:00
|
|
|
// Package provider is an external auth provider e.g oauth
|
|
|
|
package provider
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Provider is an auth provider
|
|
|
|
type Provider interface {
|
|
|
|
// String returns the name of the provider
|
|
|
|
String() string
|
|
|
|
// Options returns the options of a provider
|
|
|
|
Options() Options
|
|
|
|
// Endpoint for the provider
|
2020-04-01 15:36:22 +01:00
|
|
|
Endpoint(...EndpointOption) string
|
2020-03-07 11:06:57 +00:00
|
|
|
// Redirect url incase of UI
|
|
|
|
Redirect() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grant is a granted authorisation
|
|
|
|
type Grant struct {
|
|
|
|
// token for reuse
|
|
|
|
Token string
|
|
|
|
// Expiry of the token
|
|
|
|
Expiry time.Time
|
|
|
|
// Scopes associated with grant
|
|
|
|
Scopes []string
|
|
|
|
}
|
2020-04-01 15:36:22 +01:00
|
|
|
|
|
|
|
type EndpointOptions struct {
|
2020-04-21 13:37:26 +01:00
|
|
|
// State is a code to verify the req
|
2020-04-01 17:11:46 +01:00
|
|
|
State string
|
2020-04-21 13:37:26 +01:00
|
|
|
// LoginHint prefils the user id on oauth clients
|
|
|
|
LoginHint string
|
2020-04-01 15:36:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type EndpointOption func(*EndpointOptions)
|
|
|
|
|
2020-04-01 17:11:46 +01:00
|
|
|
func WithState(c string) EndpointOption {
|
2020-04-01 15:36:22 +01:00
|
|
|
return func(o *EndpointOptions) {
|
2020-04-01 17:11:46 +01:00
|
|
|
o.State = c
|
2020-04-01 15:36:22 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-21 13:37:26 +01:00
|
|
|
|
|
|
|
func WithLoginHint(hint string) EndpointOption {
|
|
|
|
return func(o *EndpointOptions) {
|
|
|
|
o.LoginHint = hint
|
|
|
|
}
|
|
|
|
}
|