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

View file

@ -0,0 +1,29 @@
package flows
import (
opaal "davidallendj/opaal/internal"
"fmt"
)
func ClientCredentials(config *opaal.Config, server *opaal.Server, client *opaal.Client) error {
// register a new OAuth 2 client with authorization srever
_, err := client.RegisterOAuthClient(config.ActionUrls.RegisterClient, nil)
if err != nil {
return fmt.Errorf("failed to register OAuth client: %v", err)
}
// authorize the client
_, err = client.AuthorizeClient(config.ActionUrls.AuthorizeClient)
if err != nil {
return fmt.Errorf("failed to authorize client: %v", err)
}
// request a token from the authorization server
res, err := client.FetchTokenFromAuthorizationServer(config.ActionUrls.AccessToken, "", nil)
if err != nil {
return fmt.Errorf("failed to fetch token from authorization server: %v", err)
}
fmt.Printf("token: %v\n", string(res))
return nil
}