mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 16:59:22 +02:00
authorize: use opa for policy engine (#474)
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
parent
111aa8f4d5
commit
2f13488598
45 changed files with 1022 additions and 872 deletions
|
@ -125,21 +125,21 @@ func getCookies(r *http.Request, name string) []*http.Cookie {
|
|||
}
|
||||
|
||||
// LoadSession returns a State from the cookie in the request.
|
||||
func (cs *Store) LoadSession(r *http.Request) (*sessions.State, error) {
|
||||
func (cs *Store) LoadSession(r *http.Request) (*sessions.State, string, error) {
|
||||
cookies := getCookies(r, cs.Name)
|
||||
if len(cookies) == 0 {
|
||||
return nil, sessions.ErrNoSessionFound
|
||||
return nil, "", sessions.ErrNoSessionFound
|
||||
}
|
||||
for _, cookie := range cookies {
|
||||
data := loadChunkedCookie(r, cookie)
|
||||
jwt := loadChunkedCookie(r, cookie)
|
||||
|
||||
session := &sessions.State{}
|
||||
err := cs.decoder.Unmarshal([]byte(data), session)
|
||||
err := cs.decoder.Unmarshal([]byte(jwt), session)
|
||||
if err == nil {
|
||||
return session, nil
|
||||
return session, jwt, nil
|
||||
}
|
||||
}
|
||||
return nil, sessions.ErrMalformed
|
||||
return nil, "", sessions.ErrMalformed
|
||||
}
|
||||
|
||||
// SaveSession saves a session state to a request's cookie store.
|
||||
|
|
|
@ -138,7 +138,7 @@ func TestStore_SaveSession(t *testing.T) {
|
|||
r.AddCookie(cookie)
|
||||
}
|
||||
|
||||
state, err := s.LoadSession(r)
|
||||
state, _, err := s.LoadSession(r)
|
||||
if (err != nil) != tt.wantLoadErr {
|
||||
t.Errorf("LoadSession() error = %v, wantErr %v", err, tt.wantLoadErr)
|
||||
return
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
|
||||
func testAuthorizer(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := sessions.FromContext(r.Context())
|
||||
_, _, err := sessions.FromContext(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusUnauthorized)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue