mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-30 09:27:19 +02:00
authorize: support authenticating with idp tokens (#5484)
* identity: add support for verifying access and identity tokens * allow overriding with policy option * authenticate: add verify endpoints * wip * implement session creation * add verify test * implement idp token login * fix tests * add pr permission * make session ids route-specific * rename method * add test * add access token test * test for newUserFromIDPClaims * more tests * make the session id per-idp * use type for * add test * remove nil checks
This commit is contained in:
parent
6e22b7a19a
commit
b9fd926618
36 changed files with 2791 additions and 885 deletions
76
authenticate/handlers_verify.go
Normal file
76
authenticate/handlers_verify.go
Normal file
|
@ -0,0 +1,76 @@
|
|||
package authenticate
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/httputil"
|
||||
"github.com/pomerium/pomerium/internal/log"
|
||||
"github.com/pomerium/pomerium/pkg/authenticateapi"
|
||||
)
|
||||
|
||||
func (a *Authenticate) verifyAccessToken(w http.ResponseWriter, r *http.Request) error {
|
||||
var req authenticateapi.VerifyAccessTokenRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
return httputil.NewError(http.StatusBadRequest, err)
|
||||
}
|
||||
|
||||
authenticator, err := a.cfg.getIdentityProvider(r.Context(), a.tracerProvider, a.options.Load(), req.IdentityProviderID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var res authenticateapi.VerifyTokenResponse
|
||||
claims, err := authenticator.VerifyAccessToken(r.Context(), req.AccessToken)
|
||||
if err == nil {
|
||||
res.Valid = true
|
||||
res.Claims = claims
|
||||
} else {
|
||||
res.Valid = false
|
||||
log.Ctx(r.Context()).Info().
|
||||
Err(err).
|
||||
Str("idp", authenticator.Name()).
|
||||
Msg("access token failed verification")
|
||||
}
|
||||
|
||||
err = json.NewEncoder(w).Encode(&res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Authenticate) verifyIdentityToken(w http.ResponseWriter, r *http.Request) error {
|
||||
var req authenticateapi.VerifyIdentityTokenRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
return httputil.NewError(http.StatusBadRequest, err)
|
||||
}
|
||||
|
||||
authenticator, err := a.cfg.getIdentityProvider(r.Context(), a.tracerProvider, a.options.Load(), req.IdentityProviderID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var res authenticateapi.VerifyTokenResponse
|
||||
claims, err := authenticator.VerifyIdentityToken(r.Context(), req.IdentityToken)
|
||||
if err == nil {
|
||||
res.Valid = true
|
||||
res.Claims = claims
|
||||
} else {
|
||||
res.Valid = false
|
||||
log.Ctx(r.Context()).Info().
|
||||
Err(err).
|
||||
Str("idp", authenticator.Name()).
|
||||
Msg("identity token failed verification")
|
||||
}
|
||||
|
||||
err = json.NewEncoder(w).Encode(&res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue