Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit 69c85d4

Browse files
Alex KalyvitisAlex Kalyvitis
authored andcommitted
Merge branch 'mcalster-master' into master
2 parents f111ef8 + 5a007f2 commit 69c85d4

File tree

7 files changed

+156
-2
lines changed

7 files changed

+156
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## 0.15.0 (Unreleased)
1+
## 0.15.0 (September 24, 2020)
2+
3+
ENHANCEMENTS:
4+
5+
* resource/auth0_connection: Support for `oauth2` connection options ([#267](https://github.com/alexkappa/terraform-provider-auth0/pull/267)).
6+
27
## 0.14.0 (August 24, 2020)
38

49
ENHANCEMENTS:

auth0/resource_auth0_connection.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ var connectionSchema = map[string]*schema.Schema{
191191
Optional: true,
192192
Description: "",
193193
},
194+
"scripts": {
195+
Type: schema.TypeMap,
196+
Elem: &schema.Schema{Type: schema.TypeString},
197+
Optional: true,
198+
Description: "",
199+
},
194200
"configuration": {
195201
Type: schema.TypeMap,
196202
Elem: &schema.Schema{Type: schema.TypeString},

auth0/resource_auth0_connection_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,86 @@ resource "auth0_connection" "oidc" {
358358
}
359359
`
360360

361+
func TestAccConnectionOAuth2(t *testing.T) {
362+
363+
rand := random.String(6)
364+
365+
resource.Test(t, resource.TestCase{
366+
Providers: map[string]terraform.ResourceProvider{
367+
"auth0": Provider(),
368+
},
369+
Steps: []resource.TestStep{
370+
{
371+
Config: random.Template(testAccConnectionOAuth2Config, rand),
372+
Check: resource.ComposeTestCheckFunc(
373+
random.TestCheckResourceAttr("auth0_connection.oauth2", "name", "Acceptance-Test-OAuth2-{{.random}}", rand),
374+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "strategy", "oauth2"),
375+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.client_id", "123456"),
376+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.client_secret", "123456"),
377+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.token_endpoint", "https://api.login.yahoo.com/oauth2/get_token"),
378+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.authorization_endpoint", "https://api.login.yahoo.com/oauth2/request_auth"),
379+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scopes.#", "3"),
380+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scopes.2517049750", "openid"),
381+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scopes.4080487570", "profile"),
382+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scopes.881205744", "email"),
383+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scripts.fetchUserProfile", "function( { return callback(null) }"),
384+
),
385+
},
386+
{
387+
Config: random.Template(testAccConnectionOAuth2ConfigUpdate, rand),
388+
Check: resource.ComposeTestCheckFunc(
389+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.client_id", "1234567"),
390+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.client_secret", "1234567"),
391+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.token_endpoint", "https://api.paypal.com/v1/oauth2/token"),
392+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.authorization_endpoint", "https://www.paypal.com/signin/authorize"),
393+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scopes.#", "2"),
394+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scopes.2517049750", "openid"),
395+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scopes.881205744", "email"),
396+
resource.TestCheckResourceAttr("auth0_connection.oauth2", "options.0.scripts.fetchUserProfile", "function( { return callback(null) }"),
397+
),
398+
},
399+
},
400+
})
401+
}
402+
403+
const testAccConnectionOAuth2Config = `
404+
405+
resource "auth0_connection" "oauth2" {
406+
name = "Acceptance-Test-OAuth2-{{.random}}"
407+
strategy = "oauth2"
408+
is_domain_connection = false
409+
options {
410+
client_id = "123456"
411+
client_secret = "123456"
412+
token_endpoint = "https://api.login.yahoo.com/oauth2/get_token"
413+
authorization_endpoint = "https://api.login.yahoo.com/oauth2/request_auth"
414+
scopes = [ "openid", "email", "profile" ]
415+
scripts = {
416+
fetchUserProfile= "function( { return callback(null) }"
417+
}
418+
}
419+
}
420+
`
421+
422+
const testAccConnectionOAuth2ConfigUpdate = `
423+
424+
resource "auth0_connection" "oauth2" {
425+
name = "Acceptance-Test-OAuth2-{{.random}}"
426+
strategy = "oauth2"
427+
is_domain_connection = false
428+
options {
429+
client_id = "1234567"
430+
client_secret = "1234567"
431+
token_endpoint = "https://api.paypal.com/v1/oauth2/token"
432+
authorization_endpoint = "https://www.paypal.com/signin/authorize"
433+
scopes = [ "openid", "email" ]
434+
scripts = {
435+
fetchUserProfile= "function( { return callback(null) }"
436+
}
437+
}
438+
}
439+
`
440+
361441
func TestAccConnectionWithEnbledClients(t *testing.T) {
362442

363443
rand := random.String(6)

auth0/structure_auth0_connection.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ func flattenConnectionOptions(d ResourceData, options interface{}) []interface{}
1616
m = flattenConnectionOptionsAuth0(d, o)
1717
case *management.ConnectionOptionsGoogleOAuth2:
1818
m = flattenConnectionOptionsGoogleOAuth2(o)
19+
case *management.ConnectionOptionsOAuth2:
20+
m = flattenConnectionOptionsOAuth2(o)
1921
case *management.ConnectionOptionsFacebook:
2022
m = flattenConnectionOptionsFacebook(o)
2123
case *management.ConnectionOptionsApple:
@@ -81,6 +83,17 @@ func flattenConnectionOptionsGoogleOAuth2(o *management.ConnectionOptionsGoogleO
8183
}
8284
}
8385

86+
func flattenConnectionOptionsOAuth2(o *management.ConnectionOptionsOAuth2) interface{} {
87+
return map[string]interface{}{
88+
"client_id": o.GetClientID(),
89+
"client_secret": o.GetClientSecret(),
90+
"scopes": o.Scopes(),
91+
"token_endpoint": o.GetTokenEndpoint(),
92+
"authorization_endpoint": o.GetAuthorizationEndpoint(),
93+
"scripts": o.Scripts,
94+
}
95+
}
96+
8497
func flattenConnectionOptionsFacebook(o *management.ConnectionOptionsFacebook) interface{} {
8598
return map[string]interface{}{
8699
"client_id": o.GetClientID(),
@@ -241,6 +254,8 @@ func expandConnection(d ResourceData) *management.Connection {
241254
c.Options = expandConnectionOptionsAuth0(d)
242255
case management.ConnectionStrategyGoogleOAuth2:
243256
c.Options = expandConnectionOptionsGoogleOAuth2(d)
257+
case management.ConnectionStrategyOAuth2:
258+
c.Options = expandConnectionOptionsOAuth2(d)
244259
case management.ConnectionStrategyFacebook:
245260
c.Options = expandConnectionOptionsFacebook(d)
246261
case management.ConnectionStrategyApple:
@@ -340,6 +355,20 @@ func expandConnectionOptionsGoogleOAuth2(d ResourceData) *management.ConnectionO
340355

341356
return o
342357
}
358+
func expandConnectionOptionsOAuth2(d ResourceData) *management.ConnectionOptionsOAuth2 {
359+
360+
o := &management.ConnectionOptionsOAuth2{
361+
ClientID: String(d, "client_id"),
362+
ClientSecret: String(d, "client_secret"),
363+
AuthorizationEndpoint: String(d, "authorization_endpoint"),
364+
TokenEndpoint: String(d, "token_endpoint"),
365+
}
366+
o.Scripts = Map(d, "scripts")
367+
368+
expandConnectionOptionsScopes(d, o)
369+
370+
return o
371+
}
343372

344373
func expandConnectionOptionsFacebook(d ResourceData) *management.ConnectionOptionsFacebook {
345374

docs/resources/connection.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,38 @@ With the `oidc` connection strategy, `options` supports the following arguments:
261261
* `userinfo_endpoint` - (Optional)
262262
* `authorization_endpoint` - (Optional)
263263

264+
### OAuth2
265+
266+
With the `oauth2` connection strategy, `options` supports the following arguments:
267+
268+
* `client_id` - (Optional) OIDC provider client ID.
269+
* `client_secret` - (Optional) OIDC provider client secret.
270+
* `scopes` - (Optional) Scopes required by the connection. The value must be a list, for example `["openid", "profile", "email"]`.
271+
* `token_endpoint` - (Optional)
272+
* `authorization_endpoint` - (Optional)
273+
274+
**Example**:
275+
276+
```hcl
277+
resource "auth0_connection" "oauth2" {
278+
name = "OAuth2-Connection"
279+
strategy = "oauth2"
280+
options {
281+
client_id = "<client-id>"
282+
client_secret = "<client-secret>"
283+
token_endpoint = "https://auth.example.com/oauth2/token"
284+
authorization_endpoint = "https://auth.example.com/oauth2/authorize"
285+
scripts = {
286+
fetchUserProfile = <<EOF
287+
function function(accessToken, ctx, cb) {
288+
return callback(new Error("Whoops!"))
289+
}
290+
EOF
291+
}
292+
}
293+
}
294+
```
295+
264296
### Azure AD
265297

266298
With the `waad` connection strategy, `options` supports the following arguments:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ go 1.13
55
require (
66
github.com/hashicorp/go-multierror v1.1.0
77
github.com/hashicorp/terraform-plugin-sdk v1.15.0
8-
gopkg.in/auth0.v4 v4.5.0
8+
gopkg.in/auth0.v4 v4.6.0
99
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ gopkg.in/auth0.v4 v4.4.1 h1:AGOChEbsOaGn3KyIFAefsTkxcqX28JcM/mqslF+WRXA=
350350
gopkg.in/auth0.v4 v4.4.1/go.mod h1:6ZOcoQequCmURgwJnGIX09/51deRWVRpUaUP8p1Jbpk=
351351
gopkg.in/auth0.v4 v4.5.0 h1:V3NH9rlj1RfFRSGgwk9jKZrIbOn84YTn4Bi2eZV76q4=
352352
gopkg.in/auth0.v4 v4.5.0/go.mod h1:6ZOcoQequCmURgwJnGIX09/51deRWVRpUaUP8p1Jbpk=
353+
gopkg.in/auth0.v4 v4.6.0 h1:Wuc8tgAW2l+vcQ1JnwFlK5KwbJtoABA8osug8eNS3xU=
354+
gopkg.in/auth0.v4 v4.6.0/go.mod h1:6ZOcoQequCmURgwJnGIX09/51deRWVRpUaUP8p1Jbpk=
353355
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
354356
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
355357
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=

0 commit comments

Comments
 (0)