8000 Merge pull request #2 from reugn/develop · reugn/auth-server@2d3991e · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2d3991e

Browse files
authored
Merge pull request #2 from reugn/develop
v0.2.0
2 parents f9f99d5 + 3bfa840 commit 2d3991e

File tree

19 files changed

+713
-87
lines changed

19 files changed

+713
-87
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.git
2+
.github
23
.cache
34

45
examples/

.github/workflows/build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
go-version: [1.15.x, 1.16.x]
11+
steps:
12+
- name: Setup Go
13+
uses: actions/setup-go@v2
14+
with:
15+
go-version: ${{ matrix.go-version }}
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
- name: Test
19+
run: go test ./...

.github/workflows/docker.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Create and publish a Docker image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
build-and-push-image:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v2
22+
23+
- name: Log in to the Container registry
24+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
25+
with:
26+
registry: ${{ env.REGISTRY }}
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
33+
with:
34+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
35+
36+
- name: Build and push Docker image
37+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
38+
with:
39+
context: .
40+
push: true
41+
tags: ${{ steps.meta.outputs.tags }}
42+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ COPY . .
55
RUN go get ./...
66
RUN GOOS=linux go build -ldflags="-s -w" -o ./bin/auth
77

8-
FROM alpine:3.9
8+
FROM alpine:3.14
99
WORKDIR /go/bin
1010
COPY --from=build /go/src/app/bin /go/bin
1111
COPY ./secrets ./secrets

README.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
# auth-server
2-
[![GoDoc](https://godoc.org/github.com/reugn/auth_server?status.svg)](https://godoc.org/github.com/reugn/auth_server)
2+
[![Build](https://github.com/reugn/auth-server/actions/workflows/build.yml/badge.svg)](https://github.com/reugn/auth-server/actions/workflows/build.yml)
3+
[![PkgGoDev](https://pkg.go.dev/badge/github.com/reugn/auth-server)](https://pkg.go.dev/github.com/reugn/auth-server)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/reugn/auth-server)](https://goreportcard.com/report/github.com/reugn/auth-server)
35

4-
Simple authentication and authorization server.
5-
`auth-server` can act as a proxy middleware or be configured in a stand-alone mode as well. It doesn't require any third-party software integration. Use one of the available repositories to configure backend storage, or implement one of your own.
6+
This project provides tools to set up a custom authentication and authorization server.
7+
`auth-server` can act as a proxy middleware or be configured in a stand-alone mode. It doesn't require any third-party software integration. Use one of the [available repositories](./repository) to configure backend storage, or implement one of your own.
68

79
## Introduction
810
* **Authentication** is used by a server when the server needs to know exactly who is accessing their information or site.
911
* **Authorization** is a process by which a server determines if the client has permission to use a resource or access a file.
1012

11-
Building an authentication and authorization strategy is always a challenging process.
12-
Just a number of quick questions that immediately arise:
13+
Creating an authentication and authorization strategy is always a complex process. A number of quick questions immediately arise:
14+
1315
* Should we set up separate services for authentication and authorization
1416
* How do we handle access token creation and who is responsible for this
1517
* Should we alter our REST service to support authorization flow
1618

17-
`auth-server` project tries to accumulate all those capabilities and act as a transparent authentication and authorization proxy middleware.
19+
The `auth-server` project tries to accumulate all of those capabilities and act as a transparent authentication and authorization proxy middleware.
1820

1921
## Architecture
20-
![](./images/architecture_diagram_1.png)
22+
![architecture_diagram](./images/architecture_diagram_1.png)
2123

22-
1. Client requests an access token (JWT), using a basic authentication header:
24+
1. The user requests an access token (JWT), using a basic authentication header:
2325
```
2426
GET /token HTTP/1.1
2527
Host: localhost:8081
@@ -30,7 +32,7 @@ Just a number of quick questions that immediately arise:
3032
Response body:
3133
`{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODg5MzMyNTIsImlhdCI6MTU4ODkyOTY1MiwidXNlciI6ImFkbWluIiwicm9sZSI6MX0.LUx9EYsfBZGwbEsofBTT_5Lo3Y_3lk7T8pWLv3bw-XKVOqb_GhaRkVE90QR_sI-bWTkYCFIG9cPYmMXzmPLyjbofgsqTOzH6OaXi3IqxwZRtRGFtuqMoqXkakX5n38mvI3XkIOwFkNosHrpMtIq-HdqB3tfiDJc3YMsYfPbqyRBnBYJu2K51NslGQSiqKSnS_4KeLeaqqdpC7Zdb9Fo-r7EMn3FFuyPEab1iBsrcUYG3qnsKkvDhaq_jEGHflao7dEPEWaiGvJywXWaKR6XyyGtVx0H-OPfgvh1vUCLUUci2K3xE-IxjfRrHx3dSzdqFgJq_n4bVXpO9iNVYOZLccQ","token_type":"Bearer","expires_in":3600000}`
3234
33-
3. Client sends an authenticated request to the proxy server:
35+
3. The user sends an authenticated request to the proxy server:
3436
```
3537
GET /foo HTTP/1.1
3638
Host: localhost:8081
@@ -39,8 +41,8 @@ Just a number of quick questions that immediately arise:
3941
4042
4. Proxy invokes `auth-server` as an authentication/authorization middleware. In case the token was successfully authenticated/authorized, the request will be routed to the target service. Otherwise, an auth error code will be returned to the client.
4143
42-
## Prerequisites
43-
* `auth-server` written in Golang.
44+
## Installation and Prerequisites
45+
* `auth-server` is written in Golang.
4446
To install the latest stable version of Go, visit https://golang.org/dl/
4547
4648
* To run the project using Docker, visit their [page](https://www.docker.com/get-started) to get started. Docker images are available under the [GitHub Packages](https://github.com/reugn/auth-server/packages).
@@ -56,8 +58,5 @@ To run `auth-server` as a [Traefik](https://docs.traefik.io/) middleware:
5658
* `cd examples/traefik`
5759
* `docker-compose up -d`
5860
59-
## Contributing
60-
Contributions are very welcome!
61-
6261
## License
63-
Licensed under the Apache 2.0 License.
62+
Licensed under the Apache 2.0 License.

auth/jwt_validator.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ func getClaims(token *jwt.Token) (*Claims, error) {
5555
}
5656

5757
claims := Claims{}
58-
json.Unmarshal(jsonClaims, &claims)
58+
err = json.Unmarshal(jsonClaims, &claims)
59+
if err != nil {
60+
return nil, err
61+
}
5962

6063
return &claims, nil
6164
}

go.mod

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
module github.com/reugn/auth-server
22

3-
go 1.14
3+
go 1.16
44

55
require (
6-
github.com/aerospike/aerospike-client-go v2.9.0+incompatible
6+
github.com/aerospike/aerospike-client-go/v5 v5.6.0
77
github.com/dgrijalva/jwt-go v3.2.0+incompatible
8-
github.com/onsi/ginkgo v1.12.0 // indirect
9-
github.com/onsi/gomega v1.9.0 // indirect
10-
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb // indirect
11-
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
8+
github.com/fatih/color v1.13.0 // indirect
9+
github.com/go-test/deep v1.0.7 // indirect
10+
github.com/hashicorp/errwrap v1.1.0 // indirect
11+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
12+
github.com/hashicorp/go-hclog v0.16.2 // indirect
13+
github.com/hashicorp/go-multierror v1.1.1 // indirect
14+
github.com/hashicorp/go-retryablehttp v0.6.7 // indirect
15+
github.com/hashicorp/hcl v1.0.1-vault-3 // indirect
16+
github.com/hashicorp/vault/api v1.1.2-0.20210713235431-1fc8af4c041f
17+
github.com/hashicorp/vault/sdk v0.2.2-0.20211005222123-93e045565e4a // indirect
18+
github.com/mattn/go-colorable v0.1.11 // indirect
19+
github.com/mitchellh/mapstructure v1.3.3 // indirect
20+
github.com/stretchr/testify v1.7.0 // indirect
21+
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect
22+
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
23+
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
24+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
1225
)

0 commit comments

Comments
 (0)
0