markbates / markbates/goth

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

Open
#218 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
6.6k
Forks
631
PR merge metrics
No merged PRs in 30d

Description

For users of [Buffalo](https://github.com/gobuffalo/buffalo) along with the `openidConnect` provider, the default generated code will always contain an error. See this snippet:

```go
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)`](https://github.com/markbates/goth/blob/master/providers/openidConnect/openidConnect.go#L86), 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in providers/openidConnect/openidConnect.go at New and compare its return signature with the goth.UseProviders call shown in the issue. Review the generated Buffalo OpenID Connect setup and decide how the API should handle initialization errors; done means the generated setup can compile while retaining an explicit error-handling path.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
authentication, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.