Skip to content

Commit

Permalink
fix token handling
Browse files Browse the repository at this point in the history
  • Loading branch information
1lann committed Sep 7, 2024
1 parent efa68f5 commit 69c891e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (t *Tmpauth) authCallback(w http.ResponseWriter, r *http.Request) (int, err
})
}

token, err := t.ParseAuthJWT(tokenStr, backgroundWorker.MinValidationTime())
token, err := t.ParseAuthJWT(tokenStr, "", backgroundWorker.MinValidationTime())
if err != nil {
t.DebugLog(fmt.Sprintf("failed to verify callback token: %v", err))
return t.failRedirect(w, r, ErrInvalidCallbackToken)
Expand Down Expand Up @@ -111,6 +111,7 @@ func (t *Tmpauth) authCallback(w http.ResponseWriter, r *http.Request) (int, err

// token validated, can cache now
tokenID := sha256.Sum256([]byte(wToken))
token.RawToken = wToken
t.tokenCacheMutex.Lock()
t.TokenCache[tokenID] = token
t.tokenCacheMutex.Unlock()
Expand Down
6 changes: 3 additions & 3 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (t *Tmpauth) ParseWrappedAuthJWT(tokenStr string) (*CachedToken, error) {

wToken := wTokenRaw.Claims.(*wrappedToken)

cachedToken, err = t.ParseAuthJWT(wToken.Token, minValidationTime)
cachedToken, err = t.ParseAuthJWT(wToken.Token, tokenStr, minValidationTime)
if err != nil {
return nil, err
}
Expand All @@ -159,7 +159,7 @@ func (t *Tmpauth) ParseWrappedAuthJWT(tokenStr string) (*CachedToken, error) {
return cachedToken, nil
}

func (t *Tmpauth) ParseAuthJWT(tokenStr string, minValidationTime time.Time) (*CachedToken, error) {
func (t *Tmpauth) ParseAuthJWT(tokenStr string, wrappedToken string, minValidationTime time.Time) (*CachedToken, error) {
if t.miniServerHost != "" {
return nil, errors.New("tmpauth: mini server endpoint is set, cannot parse auth JWTs")
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func (t *Tmpauth) ParseAuthJWT(tokenStr string, minValidationTime time.Time) (*C
IssuedAt: iat,
StateID: stateID,
ValidatedAt: minValidationTime,
RawToken: tokenStr,
RawToken: wrappedToken,
headersMutex: new(sync.RWMutex),
}

Expand Down

0 comments on commit 69c891e

Please sign in to comment.