mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-30 16:08:56 +00:00
* feat: oidc config * fix: oidc configurations * feat: oidc idp config * feat: add oidc config test * fix: tests * fix: tests * feat: translate new events * feat: idp eventstore * feat: idp eventstore * fix: tests * feat: command side idp * feat: query side idp * feat: idp config on org * fix: tests * feat: authz idp on org * feat: org idps * feat: login policy * feat: login policy * feat: login policy * feat: add idp func on login policy * feat: add validation to loginpolicy and idp provider * feat: add default login policy * feat: login policy on org * feat: login policy on org * fix: id config handlers * fix: id config handlers * fix: create idp on org * fix: create idp on org * fix: not existing idp config * fix: default login policy * fix: add login policy on org * fix: idp provider search on org * fix: test * fix: remove idp on org * fix: test * fix: test * fix: remove admin idp * fix: logo src as byte * fix: migration * fix: tests * Update internal/iam/repository/eventsourcing/iam.go Co-authored-by: Silvan <[email protected]> * Update internal/iam/repository/eventsourcing/iam_test.go Co-authored-by: Silvan <[email protected]> * Update internal/iam/repository/eventsourcing/iam_test.go Co-authored-by: Silvan <[email protected]> * Update internal/iam/repository/eventsourcing/model/login_policy.go Co-authored-by: Silvan <[email protected]> * Update internal/iam/repository/eventsourcing/model/login_policy.go Co-authored-by: Silvan <[email protected]> * Update internal/org/repository/eventsourcing/org_test.go Co-authored-by: Silvan <[email protected]> * Update internal/iam/repository/eventsourcing/model/login_policy_test.go Co-authored-by: Silvan <[email protected]> * Update internal/iam/repository/eventsourcing/model/login_policy_test.go Co-authored-by: Silvan <[email protected]> * fix: pr comments * fix: tests * Update types.go * fix: merge request changes * fix: reduce optimization Co-authored-by: Silvan <[email protected]> Co-authored-by: Livio Amstutz <[email protected]>
68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/caos/zitadel/internal/authz/repository/eventsourcing/view"
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
iam_event "github.com/caos/zitadel/internal/iam/repository/eventsourcing"
|
|
proj_event "github.com/caos/zitadel/internal/project/repository/eventsourcing"
|
|
)
|
|
|
|
type TokenVerifierRepo struct {
|
|
TokenVerificationKey [32]byte
|
|
IAMID string
|
|
IAMEvents *iam_event.IAMEventstore
|
|
ProjectEvents *proj_event.ProjectEventstore
|
|
View *view.View
|
|
}
|
|
|
|
func (repo *TokenVerifierRepo) VerifyAccessToken(ctx context.Context, tokenString, clientID string) (userID string, agentID string, err error) {
|
|
//TODO: use real key
|
|
tokenID, err := crypto.DecryptAESString(tokenString, string(repo.TokenVerificationKey[:32]))
|
|
if err != nil {
|
|
return "", "", caos_errs.ThrowUnauthenticated(nil, "APP-8EF0zZ", "invalid token")
|
|
}
|
|
token, err := repo.View.TokenByID(tokenID)
|
|
if err != nil {
|
|
return "", "", caos_errs.ThrowUnauthenticated(err, "APP-BxUSiL", "invalid token")
|
|
}
|
|
if !token.Expiration.After(time.Now().UTC()) {
|
|
return "", "", caos_errs.ThrowUnauthenticated(err, "APP-k9KS0", "invalid token")
|
|
}
|
|
|
|
for _, aud := range token.Audience {
|
|
if clientID == aud {
|
|
return token.UserID, token.UserAgentID, nil
|
|
}
|
|
}
|
|
return "", "", caos_errs.ThrowUnauthenticated(nil, "APP-Zxfako", "invalid audience")
|
|
}
|
|
|
|
func (repo *TokenVerifierRepo) ProjectIDAndOriginsByClientID(ctx context.Context, clientID string) (projectID string, origins []string, err error) {
|
|
app, err := repo.View.ApplicationByOIDCClientID(clientID)
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
return app.ProjectID, app.OriginAllowList, nil
|
|
}
|
|
|
|
func (repo *TokenVerifierRepo) ExistsOrg(ctx context.Context, orgID string) error {
|
|
_, err := repo.View.OrgByID(orgID)
|
|
return err
|
|
}
|
|
|
|
func (repo *TokenVerifierRepo) VerifierClientID(ctx context.Context, appName string) (string, error) {
|
|
iam, err := repo.IAMEvents.IAMByID(ctx, repo.IAMID)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
app, err := repo.View.ApplicationByProjecIDAndAppName(iam.IAMProjectID, appName)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return app.OIDCClientID, nil
|
|
}
|