mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-20 03:27:02 -07:00
Refactor and added ability to use include multiple providers in config
This commit is contained in:
parent
53d1a8cc35
commit
4bca62ec2f
13 changed files with 660 additions and 712 deletions
37
internal/login.go
Normal file
37
internal/login.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue