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

Add scope getter/setter to google-apps connection options #221

Merged
merged 4 commits into from
Jun 29, 2021

Conversation

mattoddie
Copy link
Contributor

@mattoddie mattoddie commented Jun 15, 2021

Proposed Changes

  • Add scope getter/setter to google-apps connection options

Acceptance Test Output

$ go test ./... -v -run TestConnection
testing: warning: no tests to run
PASS
ok  	gopkg.in/auth0.v5	(cached) [no tests to run]
testing: warning: no tests to run
PASS
ok  	gopkg.in/auth0.v5/internal/client	(cached) [no tests to run]
testing: warning: no tests to run
PASS
ok  	gopkg.in/auth0.v5/internal/tag	(cached) [no tests to run]
testing: warning: no tests to run
PASS
ok  	gopkg.in/auth0.v5/internal/testing/expect	(cached) [no tests to run]
=== RUN   TestConnection
=== RUN   TestConnection/Create
    connection_test.go:31: {
          "id": "con_q7rPRWu5imhYPqhv",
          "name": "Test-Connection-1624265592",
          "strategy": "auth0",
          "is_domain_connection": false,
          "realms": [
            "Test-Connection-1624265592"
          ],
          "options": {
            "mfa": {
              "active": true,
              "return_enroll_settings": true
            },
            "passwordPolicy": "good",
            "brute_force_protection": true,
            "strategy_version": 2
          }
        }
=== RUN   TestConnection/Read
    connection_test.go:39: {
          "id": "con_q7rPRWu5imhYPqhv",
          "name": "Test-Connection-1624265592",
          "strategy": "auth0",
          "is_domain_connection": false,
          "realms": [
            "Test-Connection-1624265592"
          ],
          "options": {
            "mfa": {
              "active": true,
              "return_enroll_settings": true
            },
            "passwordPolicy": "good",
            "brute_force_protection": true,
            "strategy_version": 2
          }
        }
=== RUN   TestConnection/List
    connection_test.go:91: con_cfvW7DbdXsN6iDa1 google-oauth2 *management.ConnectionOptionsGoogleOAuth2
    connection_test.go:91: con_q7rPRWu5imhYPqhv Test-Connection-1624265592 *management.ConnectionOptions
    connection_test.go:91: con_dZwLgyqQh0cWT67t Username-Password-Authentication *management.ConnectionOptions
=== RUN   TestConnection/Update
    connection_test.go:120: {
          "id": "con_q7rPRWu5imhYPqhv",
          "name": "Test-Connection-1624265592",
          "strategy": "auth0",
          "is_domain_connection": false,
          "realms": [
            "Test-Connection-1624265592"
          ],
          "options": {
            "brute_force_protection": true,
            "import_mode": false,
            "disable_signup": true,
            "requires_username": false,
            "customScripts": {
              "get_user": "function( { return callback(null) }"
            },
            "configuration": {
              "foo": "2.0$e2e56445823bf15d86109342428b55f6$1226ddcae8fa9a6b74c7390a660357a0$ffd0a1792224b79101773b1530a7d443a928a6282a00ac74eb23896757bdf88e"
            },
            "non_persistent_attrs": [
              "ethnicity",
              "gender"
            ]
          }
        }
=== RUN   TestConnection/Delete
=== RUN   TestConnection/ReadByName
    connection_test.go:135: {
          "id": "con_dZwLgyqQh0cWT67t",
          "name": "Username-Password-Authentication",
          "strategy": "auth0",
          "is_domain_connection": false,
          "enabled_clients": [
            "oRfcKBXlY8txT5DTMMLvwJD9PAigkF8o",
            "u6oFHgh41FGhKeJuu5CfgEzFhyTUWGdn",
            "WnNGST10Ub52ebebwWNgm55FWAYXpsQZ"
          ],
          "realms": [
            "Username-Password-Authentication"
          ],
          "options": {
            "mfa": {
              "active": true,
              "return_enroll_settings": true
            },
            "validation": {
              "username": {
                "max": 15,
                "min": 1
              }
            },
            "passwordPolicy": "good",
            "password_history": {
              "enable": false,
              "size": 5
            },
            "password_no_personal_info": {
              "enable": false
            },
            "password_dictionary": {
              "dictionary": [],
              "enable": false
            },
            "password_complexity_options": {
              "min_length": 8
            },
            "enabledDatabaseCustomization": false,
            "brute_force_protection": true,
            "import_mode": false,
            "requires_username": true,
            "customScripts": {
              "change_password": "function changePassword(email, newPassword, callback) {\n  // This script should change the password stored for the current user in your\n  // database. It is executed when the user clicks on the confirmation link\n  // after a reset password request.\n  // The content and behavior of password confirmation emails can be customized\n  // here: https://manage.auth0.com/#/emails\n  // The `newPassword` parameter of this function is in plain text. It must be\n  // hashed/salted to match whatever is stored in your database.\n  //\n  // There are three ways that this script can finish:\n  // 1. The user's password was updated successfully:\n  //     callback(null, true);\n  // 2. The user's password was not updated:\n  //     callback(null, false);\n  // 3. Something went wrong while trying to reach your database:\n  //     callback(new Error(\"my error message\"));\n  //\n  // If an error is returned, it will be passed to the query string of the page\n  // where the user is being redirected to after clicking the confirmation link.\n  // For example, returning `callback(new Error(\"error\"))` and redirecting to\n  // https://example.com would redirect to the following URL:\n  //     https://example.com?email=alice%40example.com\u0026message=error\u0026success=false\n\n  const msg = 'Please implement the Change Password script for this database ' +\n    'connection at https://manage.auth0.com/#/connections/database';\n  return callback(new Error(msg));\n}\n",
              "create": "function create(user, callback) {\n  // This script should create a user entry in your existing database. It will\n  // be executed when a user attempts to sign up, or when a user is created\n  // through the Auth0 dashboard or API.\n  // When this script has finished executing, the Login script will be\n  // executed immediately afterwards, to verify that the user was created\n  // successfully.\n  //\n  // The user object will always contain the following properties:\n  // * email: the user's email\n  // * password: the password entered by the user, in plain text\n  // * tenant: the name of this Auth0 account\n  // * client_id: the client ID of the application where the user signed up, or\n  //              API key if created through the API or Auth0 dashboard\n  // * connection: the name of this database connection\n  //\n  // There are three ways this script can finish:\n  // 1. A user was successfully created\n  //     callback(null);\n  // 2. This user already exists in your database\n  //     callback(new ValidationError(\"user_exists\", \"my error message\"));\n  // 3. Something went wrong while trying to reach your database\n  //     callback(new Error(\"my error message\"));\n\n  const msg = 'Please implement the Create script for this database connection ' +\n    'at https://manage.auth0.com/#/connections/database';\n  return callback(new Error(msg));\n}\n",
              "delete": "function remove(id, callback) {\n  // This script remove a user from your existing database.\n  // It is executed whenever a user is deleted from the API or Auth0 dashboard.\n  //\n  // There are two ways that this script can finish:\n  // 1. The user was removed successfully:\n  //     callback(null);\n  // 2. Something went wrong while trying to reach your database:\n  //     callback(new Error(\"my error message\"));\n\n  const msg = 'Please implement the Delete script for this database ' +\n    'connection at https://manage.auth0.com/#/connections/database';\n  return callback(new Error(msg));\n}\n",
              "get_user": "function getByEmail(email, callback) {\n  // This script should retrieve a user profile from your existing database,\n  // without authenticating the user.\n  // It is used to check if a user exists before executing flows that do not\n  // require authentication (signup and password reset).\n  //\n  // There are three ways this script can finish:\n  // 1. A user was successfully found. The profile should be in the following\n  // format: https://auth0.com/docs/users/normalized/auth0/normalized-user-profile-schema.\n  //     callback(null, profile);\n  // 2. A user was not found\n  //     callback(null);\n  // 3. Something went wrong while trying to reach your database:\n  //     callback(new Error(\"my error message\"));\n\n  const msg = 'Please implement the Get User script for this database connection ' +\n    'at https://manage.auth0.com/#/connections/database';\n  return callback(new Error(msg));\n}\n",
              "login": "function login(email, password, callback) {\n  // This script should authenticate a user against the credentials stored in\n  // your database.\n  // It is executed when a user attempts to log in or immediately after signing\n  // up (as a verification that the user was successfully signed up).\n  //\n  // Everything returned by this script will be set as part of the user profile\n  // and will be visible by any of the tenant admins. Avoid adding attributes\n  // with values such as passwords, keys, secrets, etc.\n  //\n  // The `password` parameter of this function is in plain text. It must be\n  // hashed/salted to match whatever is stored in your database. For example:\n  //\n  //     var bcrypt = require('bcrypt@0.8.5');\n  //     bcrypt.compare(password, dbPasswordHash, function(err, res)) { ... }\n  //\n  // There are three ways this script can finish:\n  // 1. The user's credentials are valid. The returned user profile should be in\n  // the following format: https://auth0.com/docs/users/normalized/auth0/normalized-user-profile-schema\n  //     var profile = {\n  //       user_id: ..., // user_id is mandatory\n  //       email: ...,\n  //       [...]\n  //     };\n  //     callback(null, profile);\n  // 2. The user's credentials are invalid\n  //     callback(new WrongUsernameOrPasswordError(email, \"my error message\"));\n  // 3. Something went wrong while trying to reach your database\n  //     callback(new Error(\"my error message\"));\n  //\n  // A list of Node.js modules which can be referenced is available here:\n  //\n  //    https://tehsis.github.io/webtaskio-canirequire/\n\n  const msg = 'Please implement the Login script for this database connection ' +\n    'at https://manage.auth0.com/#/connections/database';\n  return callback(new Error(msg));\n}\n",
              "verify": "function verify(email, callback) {\n  // This script should mark the current user's email address as verified in\n  // your database.\n  // It is executed whenever a user clicks the verification link sent by email.\n  // These emails can be customized at https://manage.auth0.com/#/emails.\n  // It is safe to assume that the user's email already exists in your database,\n  // because verification emails, if enabled, are sent immediately after a\n  // successful signup.\n  //\n  // There are two ways that this script can finish:\n  // 1. The user's email was verified successfully\n  //     callback(null, true);\n  // 2. Something went wrong while trying to reach your database:\n  //     callback(new Error(\"my error message\"));\n  //\n  // If an error is returned, it will be passed to the query string of the page\n  // where the user is being redirected to after clicking the verification link.\n  // For example, returning `callback(new Error(\"error\"))` and redirecting to\n  // https://example.com would redirect to the following URL:\n  //     https://example.com?email=alice%40example.com\u0026message=error\u0026success=false\n\n  const msg = 'Please implement the Verify script for this database connection ' +\n    'at https://manage.auth0.com/#/connections/database';\n  return callback(new Error(msg));\n}\n"
            },
            "strategy_version": 2
          }
        }
=== RUN   TestConnection/ReadByNameEmptyName
    connection_test.go:153: null
--- PASS: TestConnection (1.02s)
    --- PASS: TestConnection/Create (0.42s)
    --- PASS: TestConnection/Read (0.10s)
    --- PASS: TestConnection/List (0.10s)
    --- PASS: TestConnection/Update (0.15s)
    --- PASS: TestConnection/Delete (0.16s)
    --- PASS: TestConnection/ReadByName (0.09s)
    --- PASS: TestConnection/ReadByNameEmptyName (0.00s)
=== RUN   TestConnectionOptions
=== RUN   TestConnectionOptions/GoogleOAuth2
    connection_test.go:223: {
          "id": "con_4TfhtTh6zo1mil3v",
          "name": "Test-Connection-1624265593",
          "strategy": "google-oauth2",
          "is_domain_connection": false,
          "realms": [
            "Test-Connection-1624265593"
          ],
          "options": {
            "allowed_audiences": [
              "example.com",
              "api.example.com"
            ],
            "email": true,
            "profile": true,
            "calendar": true,
            "youtube": false,
            "scope": [
              "profile",
              "https://www.googleapis.com/auth/calendar",
              "email"
            ]
          }
        }
=== RUN   TestConnectionOptions/GoogleApps
    connection_test.go:288: {
          "id": "con_3hnkNmmyeXDSNCjO",
          "name": "Test-Connection-1624265600",
          "strategy": "google-apps",
          "is_domain_connection": false,
          "realms": [
            "Test-Connection-1624265600"
          ],
          "provisioning_ticket_url": "https://login.eu.auth0.com/dev-5b5-gz7c/p/google-apps/ZlPpPTdS",
          "options": {
            "tenant_domain": "example.com",
            "basic_profile": true,
            "ext_profile": true,
            "ext_groups": true
          }
        }
=== RUN   TestConnectionOptions/OIDC
=== RUN   TestConnectionOptions/OAuth2
=== RUN   TestConnectionOptions/Email
    connection_test.go:393: {
          "id": "con_NjkW654QwypqrJ0u",
          "name": "Test-Connection-Email-1624265601",
          "strategy": "email",
          "is_domain_connection": false,
          "realms": [
            "Test-Connection-Email-1624265601"
          ],
          "options": {
            "name": "Test-Connection-Email",
            "email": {
              "syntax": "liquid",
              "from": "{{application.name}} \u003ctest@example.com\u003e",
              "subject": "Email Login - {{application.name}}",
              "body": "\u003chtml\u003e\u003cbody\u003eemail contents\u003c/body\u003e\u003c/html\u003e"
            },
            "totp": {
              "time_step": 100,
              "length": 4
            },
            "authParams": {
              "scope": "openid profile"
            },
            "disable_signup": true,
            "brute_force_protection": true,
            "non_persistent_attrs": [
              "gender",
              "ethnicity",
              "favorite_color"
            ]
          }
        }
=== RUN   TestConnectionOptions/SMS
    connection_test.go:449: {
          "id": "con_cCi62DPhsbtFvFKS",
          "name": "Test-Connection-SMS-1624265608",
          "strategy": "sms",
          "is_domain_connection": false,
          "realms": [
            "Test-Connection-SMS-1624265608"
          ],
          "options": {
            "name": "Test-Connection-SMS",
            "from": "+17777777777",
            "syntax": "liquid",
            "template": "Your verification code is { code }}",
            "totp": {
              "time_step": 110,
              "length": 5
            },
            "authParams": {
              "scope": "openid profile"
            },
            "twilio_sid": "abc132asdfasdf56",
            "twilio_token": "234127asdfsada23",
            "messaging_service_sid": "273248090982390423",
            "disable_signup": true,
            "brute_force_protection": true
          }
        }
=== RUN   TestConnectionOptions/SAML
=== RUN   TestConnectionOptions/AD
--- PASS: TestConnectionOptions (21.91s)
    --- PASS: TestConnectionOptions/GoogleOAuth2 (7.07s)
    --- PASS: TestConnectionOptions/GoogleApps (0.97s)
    --- PASS: TestConnectionOptions/OIDC (0.00s)
    --- PASS: TestConnectionOptions/OAuth2 (0.00s)
    --- PASS: TestConnectionOptions/Email (6.66s)
    --- PASS: TestConnectionOptions/SMS (0.29s)
    --- PASS: TestConnectionOptions/SAML (0.31s)
    --- PASS: TestConnectionOptions/AD (6.62s)
PASS
ok  	gopkg.in/auth0.v5/management	23.108s
...

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

@yvovandoorn
Copy link
Contributor

Hi @mattoddie

Thank you for your contribution! Would you mind, similar to what is being done with the google-oauth2 strategy, to write a setting & getting the scope (e.g. set scope, then get scope and have a expect on the get scope).

Reasoning is the setter/getter is relatively undocumented for google-apps, so getting visibility on it would be good.

Thanks!

@mattoddie
Copy link
Contributor Author

mattoddie commented Jun 21, 2021

Hi @mattoddie

Thank you for your contribution! Would you mind, similar to what is being done with the google-oauth2 strategy, to write a setting & getting the scope (e.g. set scope, then get scope and have a expect on the get scope).

Reasoning is the setter/getter is relatively undocumented for google-apps, so getting visibility on it would be good.

Thanks!

@yvovandoorn I added tests that picked up an issue undefined is not a valid google apps domain so I added the tenant_domain which has resolved that.

@yvovandoorn yvovandoorn merged commit 0ed82d2 into go-auth0:master Jun 29, 2021
@mattoddie mattoddie deleted the feature/google-apps-scopes branch January 27, 2022 10:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants