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

gothic: Add http PathValue() support to GetProviderName() #589

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions gothic/gothic.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@
return p, nil
}

// try to get it from the go v1.22+ path value
if p := req.PathValue("provider"); p != "" {

Check failure on line 297 in gothic/gothic.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

req.PathValue undefined (type *http.Request has no field or method PathValue)

Check failure on line 297 in gothic/gothic.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, ubuntu-latest)

req.PathValue undefined (type *http.Request has no field or method PathValue)

Check failure on line 297 in gothic/gothic.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, macos-latest)

req.PathValue undefined (type *http.Request has no field or method PathValue)

Check failure on line 297 in gothic/gothic.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, macos-latest)

req.PathValue undefined (type *http.Request has no field or method PathValue)

Check failure on line 297 in gothic/gothic.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest)

req.PathValue undefined (type *http.Request has no field or method PathValue)

Check failure on line 297 in gothic/gothic.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

req.PathValue undefined (type *http.Request has no field or method PathValue)

Check failure on line 297 in gothic/gothic.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

req.PathValue undefined (type *http.Request has no field or method PathValue)

Check failure on line 297 in gothic/gothic.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

req.PathValue undefined (type *http.Request has no field or method PathValue)
return p, nil
}

// As a fallback, loop over the used providers, if we already have a valid session for any provider (ie. user has already begun authentication with a provider), then return that provider name
providers := goth.GetProviders()
session, _ := Store.Get(req, SessionName)
Expand Down
22 changes: 22 additions & 0 deletions gothic/gothic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,28 @@ func Test_CompleteUserAuthWithContextParamProvider(t *testing.T) {
a.Equal(user.Email, "homer@example.com")
}

func Test_CompleteUserAuthWithPathValueProvider(t *testing.T) {
a := assert.New(t)

res := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/auth/faux/callback", nil)
a.NoError(err)

req.SetPathValue("provider", "faux")

sess := faux.Session{Name: "Homer Simpson", Email: "homer@example.com"}
session, _ := Store.Get(req, SessionName)
session.Values["faux"] = gzipString(sess.Marshal())
err = session.Save(req, res)
a.NoError(err)

user, err := CompleteUserAuth(res, req)
a.NoError(err)

a.Equal(user.Name, "Homer Simpson")
a.Equal(user.Email, "homer@example.com")
}

func Test_Logout(t *testing.T) {
a := assert.New(t)

Expand Down
Loading