mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-20 03:27:02 -07:00
Separated authorization code and client credentials flows
This commit is contained in:
parent
f2e5720aaa
commit
53d1a8cc35
2 changed files with 339 additions and 0 deletions
48
internal/client_credentials.go
Normal file
48
internal/client_credentials.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package opaal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ClientCredentialsFlowParams struct {
|
||||
State string `yaml:"state"`
|
||||
ResponseType string `yaml:"response-type"`
|
||||
}
|
||||
|
||||
type ClientCredentialsFlowEndpoints struct {
|
||||
Create string
|
||||
Authorize string
|
||||
Token string
|
||||
}
|
||||
|
||||
func ClientCredentials(eps ClientCredentialsFlowEndpoints, client *Client) error {
|
||||
// register a new OAuth 2 client with authorization srever
|
||||
_, err := client.CreateOAuthClient(eps.Create, nil)
|
||||
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
|
||||
}
|
||||
|
||||
func ClientCredentialsWithConfig(config *Config, client *Client) error {
|
||||
eps := ClientCredentialsFlowEndpoints{
|
||||
Create: config.Authorization.RequestUrls.Clients,
|
||||
Authorize: config.Authorization.RequestUrls.Authorize,
|
||||
Token: config.Authorization.RequestUrls.Token,
|
||||
}
|
||||
return ClientCredentials(eps, client)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue