Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core/authenticate: refactor idp sign out (#4582)
- Loading branch information
1 parent
7211a8d
commit a0c9289
Showing
16 changed files
with
318 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/pomerium/pomerium/internal/httputil" | ||
"github.com/pomerium/pomerium/ui" | ||
) | ||
|
||
// SignedOutData is the data for the SignedOut page. | ||
type SignedOutData struct{} | ||
|
||
// ToJSON converts the data into a JSON map. | ||
func (data SignedOutData) ToJSON() map[string]interface{} { | ||
return map[string]interface{}{} | ||
} | ||
|
||
// SignedOut returns a handler that renders the signed out page. | ||
func SignedOut(data SignedOutData) http.Handler { | ||
return httputil.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error { | ||
return ui.ServePage(w, r, "SignedOut", data.ToJSON()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package auth0 | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pomerium/pomerium/internal/identity/oauth" | ||
) | ||
|
||
func TestProvider(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, clearTimeout := context.WithTimeout(context.Background(), time.Second*10) | ||
t.Cleanup(clearTimeout) | ||
|
||
var srv *httptest.Server | ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
baseURL, err := url.Parse(srv.URL + "/") | ||
require.NoError(t, err) | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
switch r.URL.Path { | ||
case "/.well-known/openid-configuration": | ||
json.NewEncoder(w).Encode(map[string]any{ | ||
"issuer": baseURL.String(), | ||
"authorization_endpoint": srv.URL + "/authorize", | ||
}) | ||
|
||
default: | ||
assert.Failf(t, "unexpected http request", "url: %s", r.URL.String()) | ||
} | ||
}) | ||
srv = httptest.NewServer(handler) | ||
t.Cleanup(srv.Close) | ||
|
||
redirectURL, err := url.Parse(srv.URL) | ||
require.NoError(t, err) | ||
|
||
p, err := New(ctx, &oauth.Options{ | ||
ProviderURL: srv.URL, | ||
RedirectURL: redirectURL, | ||
ClientID: "CLIENT_ID", | ||
ClientSecret: "CLIENT_SECRET", | ||
}) | ||
require.NoError(t, err) | ||
require.NotNil(t, p) | ||
|
||
t.Run("GetSignOutURL", func(t *testing.T) { | ||
signOutURL, err := p.GetSignOutURL("", "https://www.example.com?a=b") | ||
assert.NoError(t, err) | ||
assert.Equal(t, srv.URL+"/v2/logout?client_id=CLIENT_ID&returnTo=https%3A%2F%2Fwww.example.com%3Fa%3Db", signOutURL) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.