mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-06 22:06:19 +02:00
remove auth provider
This commit is contained in:
parent
4977aca09c
commit
d07de3751e
@ -2,7 +2,6 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/micro/go-micro/v2/auth/provider/basic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -10,9 +9,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewAuth(opts ...Option) Auth {
|
func NewAuth(opts ...Option) Auth {
|
||||||
options := Options{
|
options := Options{}
|
||||||
Provider: basic.NewProvider(),
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/micro/go-micro/v2/auth/provider"
|
|
||||||
"github.com/micro/go-micro/v2/client"
|
"github.com/micro/go-micro/v2/client"
|
||||||
"github.com/micro/go-micro/v2/store"
|
"github.com/micro/go-micro/v2/store"
|
||||||
)
|
)
|
||||||
@ -34,10 +33,6 @@ type Options struct {
|
|||||||
PublicKey string
|
PublicKey string
|
||||||
// PrivateKey for encoding JWTs
|
// PrivateKey for encoding JWTs
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
// Provider is an auth provider
|
|
||||||
Provider provider.Provider
|
|
||||||
// LoginURL is the relative url path where a user can login
|
|
||||||
LoginURL string
|
|
||||||
// Store to back auth
|
// Store to back auth
|
||||||
Store store.Store
|
Store store.Store
|
||||||
// Client to use for RPC
|
// Client to use for RPC
|
||||||
@ -98,20 +93,6 @@ func ClientToken(token *Token) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provider set the auth provider
|
|
||||||
func Provider(p provider.Provider) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.Provider = p
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoginURL sets the auth LoginURL
|
|
||||||
func LoginURL(url string) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.LoginURL = url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithClient sets the client to use when making requests
|
// WithClient sets the client to use when making requests
|
||||||
func WithClient(c client.Client) Option {
|
func WithClient(c client.Client) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package basic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/micro/go-micro/v2/auth/provider"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewProvider returns an initialised basic provider
|
|
||||||
func NewProvider(opts ...provider.Option) provider.Provider {
|
|
||||||
var options provider.Options
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&options)
|
|
||||||
}
|
|
||||||
return &basic{options}
|
|
||||||
}
|
|
||||||
|
|
||||||
type basic struct {
|
|
||||||
opts provider.Options
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *basic) String() string {
|
|
||||||
return "basic"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *basic) Options() provider.Options {
|
|
||||||
return b.opts
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *basic) Endpoint(...provider.EndpointOption) string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *basic) Redirect() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
package oauth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"github.com/micro/go-micro/v2/auth/provider"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewProvider returns an initialised oauth provider
|
|
||||||
func NewProvider(opts ...provider.Option) provider.Provider {
|
|
||||||
var options provider.Options
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&options)
|
|
||||||
}
|
|
||||||
return &oauth{options}
|
|
||||||
}
|
|
||||||
|
|
||||||
type oauth struct {
|
|
||||||
opts provider.Options
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *oauth) String() string {
|
|
||||||
return "oauth"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *oauth) Options() provider.Options {
|
|
||||||
return o.opts
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *oauth) Endpoint(opts ...provider.EndpointOption) string {
|
|
||||||
var options provider.EndpointOptions
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&options)
|
|
||||||
}
|
|
||||||
|
|
||||||
params := make(url.Values)
|
|
||||||
params.Add("response_type", "code")
|
|
||||||
|
|
||||||
if len(options.State) > 0 {
|
|
||||||
params.Add("state", options.State)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(options.LoginHint) > 0 {
|
|
||||||
params.Add("login_hint", options.LoginHint)
|
|
||||||
}
|
|
||||||
|
|
||||||
if clientID := o.opts.ClientID; len(clientID) > 0 {
|
|
||||||
params.Add("client_id", clientID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if scope := o.opts.Scope; len(scope) > 0 {
|
|
||||||
params.Add("scope", scope)
|
|
||||||
}
|
|
||||||
|
|
||||||
if redir := o.Redirect(); len(redir) > 0 {
|
|
||||||
params.Add("redirect_uri", redir)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("%v?%v", o.opts.Endpoint, params.Encode())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *oauth) Redirect() string {
|
|
||||||
return o.opts.Redirect
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package provider
|
|
||||||
|
|
||||||
// Option returns a function which sets an option
|
|
||||||
type Option func(*Options)
|
|
||||||
|
|
||||||
// Options a provider can have
|
|
||||||
type Options struct {
|
|
||||||
// ClientID is the application's ID.
|
|
||||||
ClientID string
|
|
||||||
// ClientSecret is the application's secret.
|
|
||||||
ClientSecret string
|
|
||||||
// Endpoint for the provider
|
|
||||||
Endpoint string
|
|
||||||
// Redirect url incase of UI
|
|
||||||
Redirect string
|
|
||||||
// Scope of the oauth request
|
|
||||||
Scope string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Credentials is an option which sets the client id and secret
|
|
||||||
func Credentials(id, secret string) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.ClientID = id
|
|
||||||
o.ClientSecret = secret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Endpoint sets the endpoint option
|
|
||||||
func Endpoint(e string) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.Endpoint = e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect sets the Redirect option
|
|
||||||
func Redirect(r string) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.Redirect = r
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scope sets the oauth scope
|
|
||||||
func Scope(s string) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.Scope = s
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
// 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
|
|
||||||
Endpoint(...EndpointOption) string
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
type EndpointOptions struct {
|
|
||||||
// State is a code to verify the req
|
|
||||||
State string
|
|
||||||
// LoginHint prefils the user id on oauth clients
|
|
||||||
LoginHint string
|
|
||||||
}
|
|
||||||
|
|
||||||
type EndpointOption func(*EndpointOptions)
|
|
||||||
|
|
||||||
func WithState(c string) EndpointOption {
|
|
||||||
return func(o *EndpointOptions) {
|
|
||||||
o.State = c
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithLoginHint(hint string) EndpointOption {
|
|
||||||
return func(o *EndpointOptions) {
|
|
||||||
o.LoginHint = hint
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user