mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-20 03:27:02 -07:00
Refactored and added client credentials flow
This commit is contained in:
parent
f912890a2d
commit
f490eb4fc4
9 changed files with 113 additions and 41 deletions
29
internal/flows/client_credentials.go
Normal file
29
internal/flows/client_credentials.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue