Support oauth codes

This commit is contained in:
Ben Toogood
2020-04-01 15:36:22 +01:00
parent 1750fd8d10
commit ae15793fc3
3 changed files with 25 additions and 6 deletions

View File

@@ -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 {