33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package archieui
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/identity"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/oidc"
|
|
)
|
|
|
|
// signInProvider returns the configured identity provider, or nil when none
|
|
// is. It does not contact the provider: an outage is a health issue, not a
|
|
// reason to stop serving.
|
|
func signInProvider(opts Options) (*oidc.Provider, error) {
|
|
if strings.TrimSpace(opts.OidcIssuer) == "" {
|
|
return nil, nil
|
|
}
|
|
return oidc.NewProvider(oidc.Config{Issuer: opts.OidcIssuer, Audience: opts.OidcAudience})
|
|
}
|
|
|
|
// dashboardLoginFlow builds the browser sign-in flow, or nil when not
|
|
// configured. The client secret is read from the named env var.
|
|
func dashboardLoginFlow(provider *oidc.Provider, opts Options) (identity.LoginFlow, error) {
|
|
if provider == nil || strings.TrimSpace(opts.OidcClientID) == "" {
|
|
return nil, nil
|
|
}
|
|
secret := ""
|
|
if name := strings.TrimSpace(opts.OidcClientSecretEnv); name != "" {
|
|
secret = os.Getenv(name)
|
|
}
|
|
return oidc.NewFlow(provider, opts.OidcClientID, secret, opts.OidcRedirectURL)
|
|
}
|