Skip to content

Commit 5fb58ba

Browse files
Refactor project structure and fix issues #60 and #67 (#70)
* Refactor project structure and fix issues #60 and #67 - Reorganized code into cmd/ and internal/ directories following Go best practices - Split authentication logic into separate modules (claims, middleware, validator) - Extracted configuration into dedicated config package - Moved API handlers into separate handlers package - Updated dependencies and build configurations - Fixed issue #67: Added CORS support with WithValidateOnOptions(false) to allow OPTIONS preflight requests - Fixed issue #60: Added comprehensive setup documentation for RBAC and M2M permissions - Added screenshots showing Auth0 Dashboard configuration steps - Updated README with detailed instructions to prevent empty permissions array Closes #60 Closes #67 * Migrate from CircleCI to GitHub Actions - Added GitHub Actions workflow for automated testing - Uses ubuntu-20.04 runner with Go 1.24 and Node.js 20 - Clones latest test scripts from main branch - Removed CircleCI configuration - Removed semgrep workflow - Maintains same test coverage with modern CI/CD platform * Add pull request template * Switch to ubuntu-latest runner for better availability * Refactor CI workflow to build and start Docker image for API tests * Add 01-Quickstart-Go-API with modern structure and test both versions - Created new 01-Quickstart-Go-API folder with refactored code using Go 1.24 and v3 SDK - Reverted 01-Authorization-RS256 to original state for backward compatibility - Updated GitHub Actions workflow to test both samples independently - Fixed all module paths and import references in new folder - Added CORS support with WithValidateOnOptions(false) - Enhanced RBAC documentation with setup screenshots - Updated .gitignore and dependabot.yml for dual-folder structure - Removed 'Available Samples' section from main README * Fix port mapping for legacy sample (3010 vs 8080)
1 parent 1cf9115 commit 5fb58ba

File tree

24 files changed

+755
-109
lines changed

24 files changed

+755
-109
lines changed

.circleci/config.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
❗ For general support or usage questions, use the Auth0 Community forums or raise a support ticket.
3+
4+
By submitting a pull request to this repository, you agree to the terms within the Auth0 Code of Conduct: https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md.
5+
-->
6+
7+
### 🔧 Changes
8+
9+
<!--
10+
Describe both what is changing and why this is important. Include:
11+
12+
- Types and methods added, deleted, deprecated, or changed
13+
- A summary of usage if this is a new feature or a change to a public API
14+
-->
15+
16+
### 📚 References
17+
18+
<!--
19+
Add relevant links supporting this change, such as:
20+
21+
- GitHub issue/PR number addressed or fixed
22+
- Auth0 Community post
23+
- StackOverflow answer
24+
- Related pull requests/issues from other repositories
25+
26+
If there are no references, simply delete this section.
27+
-->
28+
29+
### 🔬 Testing
30+
31+
<!--
32+
Describe how this can be tested by reviewers. Be specific about anything not tested and why. Include any manual steps for testing end-to-end, or for testing functionality not covered by unit tests.
33+
-->
34+
35+
### 📝 Checklist
36+
37+
- [ ] All new/changed/fixed functionality is covered by tests (or N/A)
38+
- [ ] I have added documentation for all new/changed functionality (or N/A)
39+
40+
<!--
41+
❗ All the above items are required. Pull requests with an incomplete or missing checklist will be closed.
42+
-->

.github/dependabot.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
version: 2
22
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/01-Authorization-RS256"
5+
schedule:
6+
interval: "daily"
7+
ignore:
8+
- dependency-name: "*"
9+
update-types:
10+
["version-update:semver-major", "version-update:semver-patch"]
311

4-
- package-ecosystem: "gomod"
5-
directory: "/01-Authorization-RS256"
12+
- package-ecosystem: "gomod"
13+
directory: "/01-Quickstart-Go-API"
614
schedule:
715
interval: "daily"
816
ignore:
917
- dependency-name: "*"
10-
update-types: ["version-update:semver-major", "version-update:semver-patch"]
18+
update-types:
19+
["version-update:semver-major", "version-update:semver-patch"]

.github/workflows/semgrep.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: API Tests
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
9+
jobs:
10+
test-01-authorization-rs256:
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
AUTH0_CFG: 01-Authorization-RS256
15+
SAMPLE_PATH: 01-Authorization-RS256
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: "1.19"
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: "20"
30+
31+
- name: Clone test scripts
32+
run: git clone --depth 1 https://github.com/auth0-samples/api-quickstarts-tests test
33+
34+
- name: Prepare environment variables
35+
env:
36+
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
37+
API_IDENTIFIER: ${{ secrets.API_IDENTIFIER }}
38+
run: |
39+
cd $AUTH0_CFG
40+
mv .env.example .env
41+
sed -i 's|{DOMAIN}|'$AUTH0_DOMAIN'|g' .env
42+
sed -i 's|{API_IDENTIFIER}|'$API_IDENTIFIER'|g' .env
43+
44+
- name: Install Go dependencies
45+
run: cd $AUTH0_CFG && go mod download
46+
47+
- name: Build Docker image
48+
run: cd $AUTH0_CFG && docker build -t auth0-golang-api .
49+
50+
- name: Start server in detached mode
51+
run: cd $AUTH0_CFG && docker run -d --env-file .env -p 3010:3010 auth0-golang-api
52+
53+
- name: Wait for server to be ready
54+
run: |
55+
sleep 3
56+
until $(curl --silent --head --output /dev/null --fail http://localhost:3010/api/public); do
57+
echo "Waiting for server to start..."
58+
sleep 5
59+
done
60+
61+
- name: Prepare test environment
62+
env:
63+
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
64+
API_IDENTIFIER: ${{ secrets.API_IDENTIFIER }}
65+
CLIENT_ID_SCOPES_NONE: ${{ secrets.CLIENT_ID_SCOPES_NONE }}
66+
CLIENT_SECRET_SCOPES_NONE: ${{ secrets.CLIENT_SECRET_SCOPES_NONE }}
67+
CLIENT_ID_SCOPES_READ: ${{ secrets.CLIENT_ID_SCOPES_READ }}
68+
CLIENT_SECRET_SCOPES_READ: ${{ secrets.CLIENT_SECRET_SCOPES_READ }}
69+
CLIENT_ID_SCOPES_WRITE: ${{ secrets.CLIENT_ID_SCOPES_WRITE }}
70+
CLIENT_SECRET_SCOPES_WRITE: ${{ secrets.CLIENT_SECRET_SCOPES_WRITE }}
71+
CLIENT_ID_SCOPES_READWRITE: ${{ secrets.CLIENT_ID_SCOPES_READWRITE }}
72+
CLIENT_SECRET_SCOPES_READWRITE: ${{ secrets.CLIENT_SECRET_SCOPES_READWRITE }}
73+
run: |
74+
cd test
75+
echo "AUTH0_DOMAIN=$AUTH0_DOMAIN" >> .env
76+
echo "API_IDENTIFIER=$API_IDENTIFIER" >> .env
77+
echo "AUTH0_CLIENT_ID_1=$CLIENT_ID_SCOPES_NONE" >> .env
78+
echo "AUTH0_CLIENT_SECRET_1=$CLIENT_SECRET_SCOPES_NONE" >> .env
79+
echo "AUTH0_CLIENT_ID_2=$CLIENT_ID_SCOPES_READ" >> .env
80+
echo "AUTH0_CLIENT_SECRET_2=$CLIENT_SECRET_SCOPES_READ" >> .env
81+
echo "AUTH0_CLIENT_ID_3=$CLIENT_ID_SCOPES_WRITE" >> .env
82+
echo "AUTH0_CLIENT_SECRET_3=$CLIENT_SECRET_SCOPES_WRITE" >> .env
83+
echo "AUTH0_CLIENT_ID_4=$CLIENT_ID_SCOPES_READWRITE" >> .env
84+
echo "AUTH0_CLIENT_SECRET_4=$CLIENT_SECRET_SCOPES_READWRITE" >> .env
85+
echo "API_URL=http://localhost:3010" >> .env
86+
npm install
87+
88+
- name: Run automated tests
89+
run: cd test && npm test
90+
91+
test-01-quickstart-go-api:
92+
runs-on: ubuntu-latest
93+
94+
env:
95+
AUTH0_CFG: 01-Quickstart-Go-API
96+
SAMPLE_PATH: 01-Quickstart-Go-API
97+
98+
steps:
99+
- name: Checkout repository
100+
uses: actions/checkout@v4
101+
102+
- name: Set up Go
103+
uses: actions/setup-go@v5
104+
with:
105+
go-version: "1.24"
106+
107+
- name: Set up Node.js
108+
uses: actions/setup-node@v4
109+
with:
110+
node-version: "20"
111+
112+
- name: Clone test scripts
113+
run: git clone --depth 1 https://github.com/auth0-samples/api-quickstarts-tests test
114+
115+
- name: Prepare environment variables
116+
env:
117+
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
118+
API_IDENTIFIER: ${{ secrets.API_IDENTIFIER }}
119+
run: |
120+
cd $AUTH0_CFG
121+
mv .env.example .env
122+
sed -i 's|{DOMAIN}|'$AUTH0_DOMAIN'|g' .env
123+
sed -i 's|{API_IDENTIFIER}|'$API_IDENTIFIER'|g' .env
124+
125+
- name: Install Go dependencies
126+
run: cd $AUTH0_CFG && go mod download
127+
128+
- name: Build Docker image
129+
run: cd $AUTH0_CFG && docker build -t auth0-golang-api .
130+
131+
- name: Start server in detached mode
132+
run: cd $AUTH0_CFG && docker run -d --env-file .env -p 8080:8080 auth0-golang-api
133+
134+
- name: Wait for server to be ready
135+
run: |
136+
sleep 3
137+
until $(curl --silent --head --output /dev/null --fail http://localhost:8080/api/public); do
138+
echo "Waiting for server to start..."
139+
sleep 5
140+
done
141+
142+
- name: Prepare test environment
143+
env:
144+
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
145+
API_IDENTIFIER: ${{ secrets.API_IDENTIFIER }}
146+
CLIENT_ID_SCOPES_NONE: ${{ secrets.CLIENT_ID_SCOPES_NONE }}
147+
CLIENT_SECRET_SCOPES_NONE: ${{ secrets.CLIENT_SECRET_SCOPES_NONE }}
148+
CLIENT_ID_SCOPES_READ: ${{ secrets.CLIENT_ID_SCOPES_READ }}
149+
CLIENT_SECRET_SCOPES_READ: ${{ secrets.CLIENT_SECRET_SCOPES_READ }}
150+
CLIENT_ID_SCOPES_WRITE: ${{ secrets.CLIENT_ID_SCOPES_WRITE }}
151+
CLIENT_SECRET_SCOPES_WRITE: ${{ secrets.CLIENT_SECRET_SCOPES_WRITE }}
152+
CLIENT_ID_SCOPES_READWRITE: ${{ secrets.CLIENT_ID_SCOPES_READWRITE }}
153+
CLIENT_SECRET_SCOPES_READWRITE: ${{ secrets.CLIENT_SECRET_SCOPES_READWRITE }}
154+
run: |
155+
cd test
156+
echo "AUTH0_DOMAIN=$AUTH0_DOMAIN" >> .env
157+
echo "API_IDENTIFIER=$API_IDENTIFIER" >> .env
158+
echo "AUTH0_CLIENT_ID_1=$CLIENT_ID_SCOPES_NONE" >> .env
159+
echo "AUTH0_CLIENT_SECRET_1=$CLIENT_SECRET_SCOPES_NONE" >> .env
160+
echo "AUTH0_CLIENT_ID_2=$CLIENT_ID_SCOPES_READ" >> .env
161+
echo "AUTH0_CLIENT_SECRET_2=$CLIENT_SECRET_SCOPES_READ" >> .env
162+
echo "AUTH0_CLIENT_ID_3=$CLIENT_ID_SCOPES_WRITE" >> .env
163+
echo "AUTH0_CLIENT_SECRET_3=$CLIENT_SECRET_SCOPES_WRITE" >> .env
164+
echo "AUTH0_CLIENT_ID_4=$CLIENT_ID_SCOPES_READWRITE" >> .env
165+
echo "AUTH0_CLIENT_SECRET_4=$CLIENT_SECRET_SCOPES_READWRITE" >> .env
166+
echo "API_URL=http://localhost:8080" >> .env
167+
npm install
168+
169+
- name: Run automated tests
170+
run: cd test && npm test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.DS_Store
22
01-Authorization-RS256/.env
33
01-Authorization-RS256/vendor/
4+
01-Quickstart-Go-API/.env
5+
01-Quickstart-Go-API/vendor/

01-Quickstart-Go-API/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
README.md
2+
exec.sh
3+
exec.ps1

01-Quickstart-Go-API/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AUTH0_DOMAIN={DOMAIN}
2+
AUTH0_AUDIENCE={API_IDENTIFIER}

01-Quickstart-Go-API/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM golang:1.24-alpine
2+
3+
# Install git
4+
RUN apk --update add \
5+
git openssl \
6+
&& rm /var/cache/apk/*
7+
8+
# Define current working directory
9+
WORKDIR /01-Quickstart-Go-API
10+
11+
# Download modules to local cache so we can skip re-
12+
# downloading on consecutive docker build commands
13+
COPY go.mod .
14+
COPY go.sum .
15+
RUN go mod download
16+
17+
# Add sources
18+
COPY . .
19+
20+
# Expose port 8080 for our api binary
21+
EXPOSE 8080
22+
23+
CMD ["go", "run", "cmd/server/main.go"]

0 commit comments

Comments
 (0)