Skip to content

Commit 267ce3d

Browse files
authored
feat: support login with custom origin (#536)
1 parent 93b1d28 commit 267ce3d

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

cloudfoundry/managers/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package managers
33
// Config -
44
type Config struct {
55
Endpoint string
6+
Origin string
67
User string
78
Password string
89
SSOPasscode string

cloudfoundry/managers/session.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,20 @@ func (s *Session) init(config *configv3.Config, configUaa *configv3.Config, conf
230230
// try connecting with SSO passcode to retrieve access token and refresh token
231231
accessToken, refreshToken, err = uaaClient.Authenticate(map[string]string{
232232
"passcode": configSess.SSOPasscode,
233-
}, "", constant.GrantTypePassword)
233+
}, configSess.Origin, constant.GrantTypePassword)
234234
errType = "SSO passcode"
235235
} else if config.CFUsername() != "" {
236236
// try connecting with pair given on uaa to retrieve access token and refresh token
237237
accessToken, refreshToken, err = uaaClient.Authenticate(map[string]string{
238238
"username": config.CFUsername(),
239239
"password": config.CFPassword(),
240-
}, "", constant.GrantTypePassword)
240+
}, configSess.Origin, constant.GrantTypePassword)
241241
errType = "username/password"
242242
} else if config.UAAOAuthClient() != "cf" {
243243
accessToken, refreshToken, err = uaaClient.Authenticate(map[string]string{
244244
"client_id": config.UAAOAuthClient(),
245245
"client_secret": config.UAAOAuthClientSecret(),
246-
}, "", constant.GrantTypeClientCredentials)
246+
}, configSess.Origin, constant.GrantTypeClientCredentials)
247247
errType = "client_id/client_secret"
248248
}
249249
if err != nil {
@@ -295,7 +295,7 @@ func (s *Session) init(config *configv3.Config, configUaa *configv3.Config, conf
295295
accessTokenSess, refreshTokenSess, err = uaaClientSess.Authenticate(map[string]string{
296296
"client_id": configUaa.UAAOAuthClient(),
297297
"client_secret": configUaa.UAAOAuthClientSecret(),
298-
}, "", constant.GrantTypeClientCredentials)
298+
}, configSess.Origin, constant.GrantTypeClientCredentials)
299299
}
300300

301301
if err != nil {

cloudfoundry/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func Provider() *schema.Provider {
1919
Required: true,
2020
DefaultFunc: schema.EnvDefaultFunc("CF_API_URL", ""),
2121
},
22+
"origin": &schema.Schema{
23+
Type: schema.TypeString,
24+
Optional: true,
25+
DefaultFunc: schema.EnvDefaultFunc("CF_ORIGIN", ""),
26+
},
2227
"user": &schema.Schema{
2328
Type: schema.TypeString,
2429
Optional: true,
@@ -147,6 +152,7 @@ func Provider() *schema.Provider {
147152
func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
148153
c := managers.Config{
149154
Endpoint: strings.TrimSuffix(d.Get("api_url").(string), "/"),
155+
Origin: d.Get("origin").(string),
150156
User: d.Get("user").(string),
151157
Password: d.Get("password").(string),
152158
SSOPasscode: d.Get("sso_passcode").(string),

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ The following arguments are supported:
4444
* `api_url` - (Required) API endpoint (e.g. [https://api.local.pcfdev.io](https://api.local.pcfdev.io)). This can also be specified
4545
with the `CF_API_URL` shell environment variable.
4646

47+
* `origin` - (Optional) Indicates the identity provider to be used for login. This can also be specified
48+
with the `CF_ORIGIN` shell environment variable.
49+
4750
* `user` - (Optional) Cloud Foundry user. Defaults to "admin". This can also be specified
4851
with the `CF_USER` shell environment variable. Unless mentionned explicitly in a resource, CF admin permissions are not required.
4952

0 commit comments

Comments
 (0)