Major refactoring and code restructure

This commit is contained in:
David Allen 2024-03-10 20:19:29 -06:00
parent 72adbe1f0d
commit 6d63211d35
No known key found for this signature in database
GPG key ID: 1D2A29322FBB6FCB
10 changed files with 454 additions and 859 deletions

View file

@ -0,0 +1,40 @@
package flows
import (
"davidallendj/opaal/internal/oauth"
"fmt"
)
type ClientCredentialsFlowParams struct {
State string `yaml:"state"`
ResponseType string `yaml:"response-type"`
}
type ClientCredentialsFlowEndpoints struct {
Create string
Authorize string
Token string
}
func NewClientCredentialsFlow(eps ClientCredentialsFlowEndpoints, client *oauth.Client) error {
// register a new OAuth 2 client with authorization srever
_, err := client.CreateOAuthClient(eps.Create)
if err != nil {
return fmt.Errorf("failed to register OAuth client: %v", err)
}
// authorize the client
_, err = client.AuthorizeOAuthClient(eps.Authorize)
if err != nil {
return fmt.Errorf("failed to authorize client: %v", err)
}
// request a token from the authorization server
res, err := client.PerformTokenGrant(eps.Token, "")
if err != nil {
return fmt.Errorf("failed to fetch token from authorization server: %v", err)
}
fmt.Printf("token: %v\n", string(res))
return nil
}