File: client_credentials.go

package info (click to toggle)
golang-github-zitadel-oidc 3.44.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,520 kB
  • sloc: makefile: 5
file content (33 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package grants

import "strings"

type clientCredentialsGrantBasic struct {
	grantType string `schema:"grant_type"`
	scope     string `schema:"scope"`
}

type clientCredentialsGrant struct {
	*clientCredentialsGrantBasic
	clientID     string `schema:"client_id"`
	clientSecret string `schema:"client_secret"`
}

// ClientCredentialsGrantBasic creates an oauth2 `Client Credentials` Grant
// sending client_id and client_secret as basic auth header
func ClientCredentialsGrantBasic(scopes ...string) *clientCredentialsGrantBasic {
	return &clientCredentialsGrantBasic{
		grantType: "client_credentials",
		scope:     strings.Join(scopes, " "),
	}
}

// ClientCredentialsGrantValues creates an oauth2 `Client Credentials` Grant
// sending client_id and client_secret as form values
func ClientCredentialsGrantValues(clientID, clientSecret string, scopes ...string) *clientCredentialsGrant {
	return &clientCredentialsGrant{
		clientCredentialsGrantBasic: ClientCredentialsGrantBasic(scopes...),
		clientID:                    clientID,
		clientSecret:                clientSecret,
	}
}