Support oauth codes
This commit is contained in:
parent
1750fd8d10
commit
ae15793fc3
@ -25,7 +25,7 @@ func (b *basic) Options() provider.Options {
|
||||
return b.opts
|
||||
}
|
||||
|
||||
func (b *basic) Endpoint() string {
|
||||
func (b *basic) Endpoint(...provider.EndpointOption) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package oauth
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/micro/go-micro/v2/auth/provider"
|
||||
)
|
||||
@ -29,17 +28,25 @@ func (o *oauth) Options() provider.Options {
|
||||
return o.opts
|
||||
}
|
||||
|
||||
func (o *oauth) Endpoint() string {
|
||||
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.Code) > 0 {
|
||||
params.Add("code", options.Code)
|
||||
}
|
||||
|
||||
if clientID := o.opts.ClientID; len(clientID) > 0 {
|
||||
params.Add("client_id", clientID)
|
||||
}
|
||||
|
||||
if scope := o.opts.Scope; len(scope) > 0 {
|
||||
// spaces are url encoded since this cannot be passed in env vars
|
||||
params.Add("scope", strings.ReplaceAll(scope, "%20", " "))
|
||||
params.Add("scope", scope)
|
||||
}
|
||||
|
||||
if redir := o.Redirect(); len(redir) > 0 {
|
||||
|
@ -12,7 +12,7 @@ type Provider interface {
|
||||
// Options returns the options of a provider
|
||||
Options() Options
|
||||
// Endpoint for the provider
|
||||
Endpoint() string
|
||||
Endpoint(...EndpointOption) string
|
||||
// Redirect url incase of UI
|
||||
Redirect() string
|
||||
}
|
||||
@ -26,3 +26,15 @@ type Grant struct {
|
||||
// Scopes associated with grant
|
||||
Scopes []string
|
||||
}
|
||||
|
||||
type EndpointOptions struct {
|
||||
Code string
|
||||
}
|
||||
|
||||
type EndpointOption func(*EndpointOptions)
|
||||
|
||||
func WithCode(c string) EndpointOption {
|
||||
return func(o *EndpointOptions) {
|
||||
o.Code = c
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user