goth icon indicating copy to clipboard operation
goth copied to clipboard

OpenIDConnect's New method returns "Provider, error" instead of just "Provider"

Open bentranter opened this issue 7 years ago • 0 comments

For users of Buffalo along with the openidConnect provider, the default generated code will always contain an error. See this snippet:

package actions

import (
	"fmt"
	"os"

	"github.com/gobuffalo/buffalo"
	"github.com/markbates/goth"
	"github.com/markbates/goth/gothic"
	"github.com/markbates/goth/providers/openidConnect"
)

func init() {
	gothic.Store = App().SessionStore

	goth.UseProviders(
		openidConnect.New(os.Getenv("OPENIDCONNECT_KEY"), os.Getenv("OPENIDCONNECT_SECRET"), fmt.Sprintf("%s%s", App().Host, "/auth/openidconnect/callback"), "REDACT", "REDACT"),
	)
}

The goth.UseProviders call expects only a Provider to be passed, but in the case of openidConnect.New(), we end up passing a Provider and error since that's what openidConnect.New() returns, so the code fails to compile.

One fix for this is to add a new function with a different name that's similar to the existing func New(clientKey, secret, callbackURL, openIDAutoDiscoveryURL string, scopes ...string) (*Provider, error), but that does not return an error (you could instead panic, or use some alternative way of dealing with the error).

That being said, I'd be happy to hear from anyone who has an alternative solution.

bentranter avatar Mar 12 '18 21:03 bentranter