Refactored and added client credentials flow

This commit is contained in:
David Allen 2024-02-29 20:14:53 -07:00
parent f912890a2d
commit f490eb4fc4
No known key found for this signature in database
GPG key ID: 1D2A29322FBB6FCB
9 changed files with 113 additions and 41 deletions

28
internal/flows/login.go Normal file
View file

@ -0,0 +1,28 @@
package flows
import (
opaal "davidallendj/opaal/internal"
"fmt"
)
func Login(config *opaal.Config) error {
if config == nil {
return fmt.Errorf("config is not valid")
}
// initialize client that will be used throughout login flow
server := opaal.NewServerWithConfig(config)
client := opaal.NewClientWithConfig(config)
fmt.Printf("grant type: %v\n", config.GrantType)
if config.GrantType == "authorization_code" {
AuthorizationCode(config, server, client)
} else if config.GrantType == "client_credentials" {
ClientCredentials(config, server, client)
} else {
return fmt.Errorf("invalid grant type")
}
return nil
}