Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip checking issuer when creating Provider. #122

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -79,11 +80,22 @@ type providerJSON struct {
UserInfoURL string `json:"userinfo_endpoint"`
}

// ProviderOptions allows modifying issuer retuned from well-known openid config.
type ProviderOptions interface {
RenderIssuer(issuer string) string
}

// ProviderOptionsFunc is an adapter to allow the use of ordinary functions as ProviderOptions
type ProviderOptionsFunc func(issuer string) string
func (f ProviderOptionsFunc) RenderIssuer(issuer string) string {
return f(issuer)
}

// NewProvider uses the OpenID Connect discovery mechanism to construct a Provider.
//
// The issuer is the URL identifier for the service. For example: "https://accounts.google.com"
// or "https://login.salesforce.com".
func NewProvider(ctx context.Context, issuer string) (*Provider, error) {
func NewProvider(ctx context.Context, issuer string, options ...ProviderOptions) (*Provider, error) {
wellKnown := strings.TrimSuffix(issuer, "/") + "/.well-known/openid-configuration"
resp, err := ctxhttp.Get(ctx, clientFromContext(ctx), wellKnown)
if err != nil {
Expand All @@ -102,7 +114,10 @@ func NewProvider(ctx context.Context, issuer string) (*Provider, error) {
return nil, fmt.Errorf("oidc: failed to decode provider discovery object: %v", err)
}
if p.Issuer != issuer {
return nil, fmt.Errorf("oidc: issuer did not match the issuer returned by provider, expected %q got %q", issuer, p.Issuer)
log.Printf("oidc: issuer did not match the issuer returned by provider, expected %q got %q", issuer, p.Issuer)
for _, opt := range options {
p.Issuer = opt.RenderIssuer(p.Issuer)
}
}
return &Provider{
issuer: p.Issuer,
Expand Down