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