Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Aug 15, 2022
2 parents c76d556 + 57bef4f commit c0a39a3
Show file tree
Hide file tree
Showing 68 changed files with 25,261 additions and 1,364 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches: [ main, develop ]

pull_request:
branches: [ main, develop ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: yarn

- run: yarn build

- run: yarn lint

- run: yarn test --reporters=jest-junit --runInBand

- name: Codecov
uses: codecov/[email protected]
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typings/
# dotenv environment variables file
.env
.env.test
!example/.env

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
90 changes: 89 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,92 @@
image:
file: .gitpod/Dockerfile

tasks:
- before: git pull -f origin main:main || true
init: |
# Setup Gitpod .env
$GITPOD_REPO_ROOT/.gitpod/scripts/env-setup.sh
# Setup DDev
$GITPOD_REPO_ROOT/.gitpod/scripts/ddev-download-images.sh
$GITPOD_REPO_ROOT/.gitpod/scripts/ddev-setup.sh
# Install Drupal
$GITPOD_REPO_ROOT/.gitpod/scripts/drupal-setup.sh
# Installing Nuxt
$GITPOD_REPO_ROOT/.gitpod/scripts/nuxt-setup.sh
# Build module
cd $GITPOD_REPO_ROOT && yarn && yarn build
command: |
# Setup Gitpod .env
$GITPOD_REPO_ROOT/.gitpod/scripts/env-setup.sh
# Start DDev
$GITPOD_REPO_ROOT/.gitpod/scripts/ddev-setup.sh
# Add OAuth2 consumer
cd $GITPOD_REPO_ROOT/example/drupal && ddev druxt-add-consumer
# Setup Nuxt
$GITPOD_REPO_ROOT/.gitpod/scripts/nuxt-setup.sh
cd $GITPOD_REPO_ROOT
# VScode xdebug extension
vscode:
extensions:
- dbaeumer.vscode-eslint
- editorconfig.editorconfig
- felixfbecker.php-debug
- octref.vetur
- EditorConfig.EditorConfig

ports:
# Drupal
- port: 8080
onOpen: ignore
visibility: public

# Nuxt/Druxt
- port: 3000
onOpen: ignore
visibility: public

# Nuxt/Druxt
- port: 3003
onOpen: ignore
visibility: public

# Currently un-notified and unsupported mailhog http port
- port: 8025
onOpen: ignore
# Currently un-notified and unsupported mailhog https port
- port: 8026
onOpen: ignore
# Currently un-notified and unsupported phpmyadmin http port
- port: 8036
onOpen: ignore
# Currently un-notified and unsupported phpmyadmin https port
- port: 8037
onOpen: ignore
# router http port that we're ignoring.
- port: 8888
onOpen: ignore
# router https port that we're ignoring.
- port: 8889
onOpen: ignore
# xdebug port
- port: 9003
onOpen: ignore

github:
prebuilds:
master: true
branches: true
pullRequests: true
pullRequestsFromForks: true
addCheck: true
addComment: false
addBadge: true
addLabel: true
16 changes: 16 additions & 0 deletions .gitpod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM gitpod/workspace-full
SHELL ["/bin/bash", "-c"]

RUN sudo apt-get -qq update

# Install ddev
RUN brew update && brew install drud/ddev/ddev

# Install latest composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN sudo php composer-setup.php --install-dir /usr/bin --filename composer
RUN php -r "unlink('composer-setup.php');"

# Install latest npm
RUN npm install -g npm
7 changes: 7 additions & 0 deletions .gitpod/scripts/ddev-download-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

ddev version | awk '/(drud|phpmyadmin)/ {print $2;}' >/tmp/images.txt
while IFS= read -r item
do
docker pull "$item"
done < <(cat /tmp/images.txt)
9 changes: 9 additions & 0 deletions .gitpod/scripts/ddev-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

DRUPAL_DIR="${GITPOD_REPO_ROOT}/example/drupal"

# Misc housekeeping before start
ddev config global --instrumentation-opt-in=true

# Start ddev
cd $DRUPAL_DIR && ddev start
7 changes: 7 additions & 0 deletions .gitpod/scripts/drupal-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -eu -o pipefail

DRUPAL_DIR="${GITPOD_REPO_ROOT}/example/drupal"

# Set up Drupal website
cd "$DRUPAL_DIR" && ddev drupal-install
4 changes: 4 additions & 0 deletions .gitpod/scripts/env-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eu -o pipefail

echo -en "OAUTH_CALLBACK=https://3000-${GITPOD_WORKSPACE_ID}.${GITPOD_WORKSPACE_CLUSTER_HOST}/callback\nOAUTH_CLIENT_ID=${GITPOD_INSTANCE_ID}" > $GITPOD_REPO_ROOT/example/.env
11 changes: 11 additions & 0 deletions .gitpod/scripts/nuxt-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Set up Druxt for use on gitpod

set -eu -o pipefail

DRUXT_DIR="${GITPOD_REPO_ROOT}/example/nuxt"

# Set up Nuxt
cd "$DRUXT_DIR" && echo "BASE_URL=$(gp url 8080)" > .env
cd "$DRUXT_DIR" && yarn
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"hostname": "0.0.0.0",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceRoot}/example/drupal"
}
}
]
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# druxt-auth

## 0.2.0

### Minor Changes

- 3ef518e: feat(#8): added support for password grant.

### Patch Changes

- 5bab97a: Enabled the Nuxt Vuex store.

## 0.1.0

### Minor Changes
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 DruxtJS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 41 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DruxtAuth

[![npm](https://badgen.net/npm/v/druxt-auth)](https://www.npmjs.com/package/druxt-auth)
[![CircleCI](https://circleci.com/gh/druxt/druxt-auth.svg?style=svg)](https://circleci.com/gh/druxt/druxt-auth)
[![CI](https://github.com/druxt/druxt-auth/actions/workflows/ci.yml/badge.svg)](https://github.com/druxt/druxt-auth/actions/workflows/ci.yml)
[![Known Vulnerabilities](https://snyk.io/test/github/druxt/druxt-auth/badge.svg?targetFile=package.json)](https://snyk.io/test/github/druxt/druxt-auth?targetFile=package.json)
[![codecov](https://codecov.io/gh/druxt/druxt-auth/branch/develop/graph/badge.svg)](https://codecov.io/gh/druxt/druxt-auth)

Expand All @@ -23,36 +23,59 @@ Add module to `nuxt.config.js`

```js
module.exports = {
buildModules: ['druxt-auth'],
buildModules: [
'druxt',
['druxt-auth', {
clientId: '[DRUPAL_CONSUMER_UUID]',
clientSecret: '[DRUPAL_CONSUMER_SECRET]',
}]
],
druxt: {
baseUrl: 'https://demo-api.druxtjs.org',
auth: {
clientId: '[DRUPAL_CONSUMER_UUID]'
},
baseUrl: 'https://demo-api.druxtjs.org'
},
}
```

_Note:_ Replace `[DRUPAL_CONSUMER_UUID]` with the UUID of the consumer created in the following step.
_Note:_ Replace `[DRUPAL_CONSUMER_UUID]` and `[DRUPAL_CONSUMER_SECRET]` with the details from the consumer created in the following step.

### Drupal

1. Download, install and setup the [Simple OAuth module](https://www.drupal.org/project/simple_oauth).
2. Create a Consumer with:
- New Secret: _leave this empty_
- Is Confidential: _unchecked_
- Use PKCE?: _checked_
- Redirect URI: `[FRONTEND_URL]/callback` (e.g., `http://localhost:3000/callback`)
2. Create a Consumer depending on your desired authorization strategy:

- **Authorization Code** grant:
- New Secret: _leave this empty_
- Is Confidential: _unchecked_
- Use PKCE?: _checked_
- Redirect URI: `[FRONTEND_URL]/callback` (e.g., `http://localhost:3000/callback`)

- **Password** grant:
- New Secret: _provide a secure secret_
- Is Confidential: _checked_
- Redirect URI: `[FRONTEND_URL]/callback` (e.g., `http://localhost:3000/callback`)

## Usage

The DruxtAuth module installs and configures the **nuxt/auth** module for your Druxt site.

It adds a `drupal-authorization_code` auth strategy that can be used via the `$auth` plugin:
It adds two auth strategies that can be used via the `$auth` plugin:
- `drupal-authorization_code`
```js
this.$nuxt.$auth.loginWith('drupal-authorization_code')
```

- `drupal-password`
```js
this.$nuxt.$auth.loginWith('drupal-password', {
data: {
username: '',
password: ''
}
})
```

_Note:_ Nuxt must be running in SSR mode for password grant, and client secret must be set.

```js
this.$nuxt.$auth.loginWith('drupal-authorization_code')
```

- See the **nuxt/auth** documentation form more details: https://auth.nuxtjs.org/api/auth

Expand All @@ -61,4 +84,5 @@ this.$nuxt.$auth.loginWith('drupal-authorization_code')

| Option | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `druxt.auth.cliendId` | `string` | Yes | `undefined` | The Drupal Consumer UUID |
| `clientId` | `string` | Yes | `undefined` | The Drupal Consumer UUID |
| `clientSecret` | `string` | No | `undefined` | The Drupal Consumer API secret. Required for Password grant. |
2 changes: 2 additions & 0 deletions example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OAUTH_CALLBACK=http://localhost:3000/callback
OAUTH_CLIENT_ID=d428854d-7d89-4756-816f-3ab1ddf7dd36
Loading

0 comments on commit c0a39a3

Please sign in to comment.