Skip to content

Commit

Permalink
authn: update handler for whoami probe
Browse files Browse the repository at this point in the history
  • Loading branch information
greenpau committed Jan 4, 2024
1 parent bd6bad9 commit dd42ae7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/authn/handle_json_whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,30 @@ import (
"go.uber.org/zap"
"net/http"
"strings"
"time"
)

func (p *Portal) handleJSONWhoami(ctx context.Context, w http.ResponseWriter, r *http.Request, rr *requests.Request, usr *user.User) error {
if usr == nil {
return p.handleJSONError(ctx, w, http.StatusUnauthorized, "Access denied")
}

// Check whether probe is being requested.
probeEnabled := r.URL.Query().Get("probe")
if probeEnabled == "true" && usr.Claims != nil {
respMap := make(map[string]interface{})
for k, v := range usr.AsMap() {
respMap[k] = v
}
expiresIn := usr.Claims.ExpiresAt - time.Now().Unix()
respMap["authenticated"] = true
respMap["expires_in"] = expiresIn
respBytes, _ := json.Marshal(respMap)
w.WriteHeader(200)
w.Write(respBytes)
return nil
}

// Check whether id_token is being requested.
identityTokenEnabled := r.URL.Query().Get("id_token")
if identityTokenEnabled != "true" || usr.Claims == nil {
Expand Down

0 comments on commit dd42ae7

Please sign in to comment.