Files
threshold/internal/auth/oidc/ids.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.8 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
2023-02-02 17:15:17 -08:00
// SPDX-License-Identifier: BUSL-1.1
2021-04-08 20:54:32 -04:00
package oidc
import (
"context"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
2021-04-08 20:54:32 -04:00
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/types/resource"
2021-04-08 20:54:32 -04:00
)
func init() {
globals.RegisterPrefixToResourceInfo(globals.OidcAuthMethodPrefix, resource.AuthMethod, auth.Domain, Subtype)
globals.RegisterPrefixToResourceInfo(globals.OidcAccountPrefix, resource.Account, auth.Domain, Subtype)
globals.RegisterPrefixToResourceInfo(globals.OidcManagedGroupPrefix, resource.ManagedGroup, auth.Domain, Subtype)
}
2023-11-02 16:03:47 -04:00
const (
Subtype = globals.Subtype("oidc")
2023-11-02 16:03:47 -04:00
)
func newAuthMethodId(ctx context.Context) (string, error) {
2021-04-08 20:54:32 -04:00
const op = "oidc.newAuthMethodId"
id, err := db.NewPublicId(ctx, globals.OidcAuthMethodPrefix)
2021-04-08 20:54:32 -04:00
if err != nil {
return "", errors.Wrap(ctx, err, op)
2021-04-08 20:54:32 -04:00
}
return id, nil
}
func newAccountId(ctx context.Context, authMethodId, issuer, sub string) (string, error) {
2021-04-08 20:54:32 -04:00
const op = "oidc.newAccountId"
if authMethodId == "" {
return "", errors.New(ctx, errors.InvalidParameter, op, "missing auth method id")
2021-04-08 20:54:32 -04:00
}
if issuer == "" {
return "", errors.New(ctx, errors.InvalidParameter, op, "missing issuer")
2021-04-08 20:54:32 -04:00
}
if sub == "" {
return "", errors.New(ctx, errors.InvalidParameter, op, "missing subject")
2021-04-08 20:54:32 -04:00
}
id, err := db.NewPublicId(ctx, globals.OidcAccountPrefix, db.WithPrngValues([]string{authMethodId, issuer, sub}))
2021-04-08 20:54:32 -04:00
if err != nil {
return "", errors.Wrap(ctx, err, op)
2021-04-08 20:54:32 -04:00
}
return id, nil
}
2021-06-01 14:12:34 -05:00
func newManagedGroupId(ctx context.Context) (string, error) {
2021-06-01 14:12:34 -05:00
const op = "oidc.newManagedGroupId"
id, err := db.NewPublicId(ctx, globals.OidcManagedGroupPrefix)
2021-06-01 14:12:34 -05:00
if err != nil {
return "", errors.Wrap(ctx, err, op)
2021-06-01 14:12:34 -05:00
}
return id, nil
}