Skip to content

Commit ccd9cd0

Browse files
authored
[#60] Add authentication (#62)
* feat(#60): add and configure simple_oauth * feat(#60): add consumer * feat(#60): add auth modules and setup * chore(#60): update install process * chore(#60): update .env method * chore(#60): fix callback url
1 parent 087485f commit ccd9cd0

13 files changed

+1275
-41
lines changed

Diff for: .gitpod.yml

+22-8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,29 @@ image:
33

44
tasks:
55
- init: |
6-
# Installing DDev and Drupal backend.
7-
.gitpod/scripts/ddev-download-images.sh
8-
.gitpod/scripts/ddev-setup.sh
9-
.gitpod/scripts/drupal-setup.sh
10-
# Installing Nuxt/Druxt frontend.
11-
.gitpod/scripts/nuxt-setup.sh
6+
# Setup Gitpod .env
7+
echo -en "OAUTH_CALLBACK=https://3000-${GITPOD_WORKSPACE_ID}.${GITPOD_WORKSPACE_CLUSTER_HOST}/callback\nOAUTH_CLIENT_ID=${GITPOD_INSTANCE_ID}" > .env
8+
9+
# Setup DDev
10+
$GITPOD_REPO_ROOT/.gitpod/scripts/ddev-download-images.sh
11+
$GITPOD_REPO_ROOT/.gitpod/scripts/ddev-setup.sh
12+
13+
# Install Drupal
14+
$GITPOD_REPO_ROOT/.gitpod/scripts/drupal-setup.sh
15+
16+
# Installing Nuxt
17+
$GITPOD_REPO_ROOT/.gitpod/scripts/nuxt-setup.sh
1218
command: |
13-
.gitpod/scripts/ddev-setup.sh
14-
.gitpod/scripts/nuxt-setup.sh
19+
# Start DDev
20+
$GITPOD_REPO_ROOT/.gitpod/scripts/ddev-setup.sh
21+
22+
# Add OAuth2 consumer
23+
cd $GITPOD_REPO_ROOT/drupal && ddev druxt-add-consumer
24+
25+
# Setup Nuxt
26+
$GITPOD_REPO_ROOT/.gitpod/scripts/nuxt-setup.sh
27+
28+
# Start Nuxt
1529
cd $GITPOD_REPO_ROOT/nuxt && NUXT_TELEMETRY_DISABLED=1 npm run dev
1630
1731
# VScode xdebug extension

Diff for: drupal/.ddev/commands/web/drupal-install

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
#!/bin/bash
22

3-
## Description: Install Drupal
3+
## Description: Installs Drupal and configures for DruxtSite.
44
## Usage: drupal-install
55
## Example: "ddev drupal-install"
66

7+
# Install composer dependencies.
78
composer install
8-
drush -y site:install --account-pass=admin --site-name='quickstart-druxt-site' standard
9+
10+
# Install a standard Drupal installation.
11+
drush -y site:install --site-name='quickstart-druxt-site' standard
12+
13+
# Enable the Druxt module.
914
drush -y pm:enable druxt
15+
16+
# Allow the anonymous user read only access to required Druxt resources.
1017
drush role:perm:add anonymous "access druxt resources"
18+
19+
# Enable the Simple OAuth module for authentication.
20+
drush -y pm:enable simple_oauth
21+
22+
# Configure and generate keys for Simple OAuth.
23+
drush -y config:set simple_oauth.settings public_key ../keys/public.key
24+
drush -y config:set simple_oauth.settings private_key ../keys/private.key
25+
drush simple-oauth:generate-keys ../keys
26+
27+
# Enable authenticated editting via JSON:API.
1128
drush -y config:set jsonapi.settings read_only 0

Diff for: drupal/.ddev/commands/web/druxt-add-consumer

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
## Description: Installs a Simple OAuth consumer for Druxt use on Gitpod.
4+
## Usage: druxt-add-consumer
5+
## Example: "ddev druxt-add-consumer"
6+
7+
# Create a Druxt consumer.
8+
drush php-eval '
9+
$consumer = \Drupal\consumers\Entity\Consumer::create([
10+
"owner_id" => 1,
11+
"uuid" => getenv("OAUTH_CLIENT_ID") ?: \Drupal::service("uuid")->generate(),
12+
"label" => "Druxt",
13+
"description" => "DruxtJS is a bridge between frameworks, Drupal in the back, Nuxt in the front.\n\nhttps://druxtjs.org",
14+
"confidential" => FALSE,
15+
"pkce" => TRUE,
16+
"redirect" => getenv("OAUTH_CALLBACK") ?: "http://localhost:3000/callback",
17+
"image_styles" => [],
18+
"roles" => [],
19+
]);
20+
$consumer->save();
21+
'

Diff for: drupal/.ddev/docker-compose.env.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3.6'
2+
3+
services:
4+
web:
5+
env_file:
6+
- "$PWD/../.env"
7+
volumes:
8+
- "$PWD/../.env:/var/www/html/.env"

Diff for: drupal/composer.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"drupal/core-project-message": "9.3.6",
2121
"drupal/core-recommended": "9.3.6",
2222
"drupal/druxt": "1.1.1",
23-
"drush/drush": "11.0.5"
23+
"drupal/simple_oauth": "^5.2",
24+
"drush/drush": "11.0.5",
25+
"vlucas/phpdotenv": "^5.4"
2426
},
2527
"require-dev": {
2628
"drupal/core-dev": "9.3.6"
@@ -30,6 +32,11 @@
3032
},
3133
"minimum-stability": "dev",
3234
"prefer-stable": true,
35+
"autoload": {
36+
"files": [
37+
"load.environment.php"
38+
]
39+
},
3340
"config": {
3441
"sort-packages": true,
3542
"allow-plugins": {

0 commit comments

Comments
 (0)