Refactor and added ability to use include multiple providers in config

This commit is contained in:
David Allen 2024-03-03 18:23:35 -07:00
parent 53d1a8cc35
commit 4bca62ec2f
No known key found for this signature in database
GPG key ID: 1D2A29322FBB6FCB
13 changed files with 660 additions and 712 deletions

37
internal/login.go Normal file
View file

@ -0,0 +1,37 @@
package opaal
import (
"davidallendj/opaal/internal/db"
"davidallendj/opaal/internal/oidc"
"fmt"
)
func Login(config *Config, client *Client, provider *oidc.IdentityProvider) error {
if config == nil {
return fmt.Errorf("config is not valid")
}
// make cache if it's not where expect
_, err := db.CreateIdentityProvidersIfNotExists(config.Options.CachePath)
if err != nil {
fmt.Printf("failed to create cache: %v\n", err)
}
if config.Options.FlowType == "authorization_code" {
// create a server if doing authorization code flow
server := NewServerWithConfig(config)
err := AuthorizationCodeWithConfig(config, server, client, provider)
if err != nil {
fmt.Printf("failed to complete authorization code flow: %v\n", err)
}
} else if config.Options.FlowType == "client_credentials" {
err := ClientCredentialsWithConfig(config, client)
if err != nil {
fmt.Printf("failed to complete client credentials flow: %v", err)
}
} else {
return fmt.Errorf("invalid grant type (options: authorization_code, client_credentials)")
}
return nil
}