markbates / markbates/goth

Decoupling from Gorilla Mux

Open
#131 7 comments 14 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

In recent months, gothic.go has become coupled to gorilla/mux. See lines 176 onward

```go
func getProviderName(req *http.Request) (string, error) {
provider := req.URL.Query().Get("provider")
if provider == "" {
if p, ok := mux.Vars(req)["provider"]; ok {
return p, nil
}
}
if provider == "" {
provider = req.URL.Query().Get(":provider")
}
if provider == "" {
return provider, errors.New("you must select a provider")
}
return provider, nil
}
```

Firstly, note that `req.URL.Query().Get(":provider")` is possibly called twice (this may be a mistake).

Secondly, `mux.Vars(req)["provider"]` is specific to gorilla/mux. I happen to use julienschmidt/httprouter and I'd quite like to decouple from gorilla/mux dependency, which I don't need in my codebase.

So, perhaps the package `gothic` is really two things: (a) it provides the main API for `goth` and (b) it provides gorilla/mux lookup of the provider variable. Combining these is unfortunate because it reduces the flexibility of the package. [There is a third concern: storage of state in the session; however I'm content to leave this unchanged.]

There are several possible options to reduce this coupling. The simplest I can think of is to do away with the `GetProviderName` method (and `getProviderName`) and change the signature of `CompleteUserAuth` to take an additional `providerName string` parameter.

It would then be quite easy to have another function that wraps `CompleteUserAuth` as a standard `http.HandlerFunc`, along with the gorilla/mux providerName expression - this would need to be in a *different* package so that gorilla/mux drops out of the imports list (note that gorilla/mux is in the list of imports and this is the key difficulty).

It would also be easy to implement different integrations with other routing libraries, which Is what I would need.

My workaround for this is to make a copy of gothic.go in my own codebase and with the necessary alteration I've described. But I'd prefer not to have to duplicate the code.

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 with gothic.go around lines 176 onward, including getProviderName, CompleteUserAuth, and the gorilla/mux import. Compare the proposed providerName parameter and separate handler approach with the existing API; done means the core package no longer requires gorilla/mux while provider lookup and authentication remain supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
authentication, backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.