Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maragudk/rest-auth-server
An example HTTP REST server with authentication and authorization.
https://github.com/maragudk/rest-auth-server
auth authentication authorization go golang
Last synced: 2 months ago
JSON representation
An example HTTP REST server with authentication and authorization.
- Host: GitHub
- URL: https://github.com/maragudk/rest-auth-server
- Owner: maragudk
- License: mit
- Created: 2020-09-15T12:18:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-25T03:23:33.000Z (almost 2 years ago)
- Last Synced: 2024-06-20T06:24:11.302Z (7 months ago)
- Topics: auth, authentication, authorization, go, golang
- Language: Go
- Homepage: https://www.maragu.dk/blog/authentication-for-rest-apis-in-go/
- Size: 11.7 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rest-auth-server
An example HTTP REST server with authentication and authorization.
See the blog post on [Authentication for REST APIs in Go](https://www.maragu.dk/blog/authentication-for-rest-apis-in-go/) for background.
## Usage
Start the server:
```shell script
make start
```### Demo
Try out the endpoints with [HTTPie](https://httpie.org):
```shell script
$ make demo
http -v --session=./session.json --verify=no https://localhost:8080/check
GET /check HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/2.2.0HTTP/1.1 401 Unauthorized
Content-Length: 27
Content-Type: text/plain; charset=utf-8
Date: Wed, 16 Sep 2020 08:18:18 GMT
X-Content-Type-Options: nosniffunauthorized, please login
http -v --session=./session.json --form --verify=no post https://localhost:8080/signup name=demo password=1234567890
POST /signup HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 29
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:8080
User-Agent: HTTPie/2.2.0name=demo&password=1234567890
HTTP/1.1 200 OK
Content-Length: 0
Date: Wed, 16 Sep 2020 08:18:18 GMThttp -v --session=./session.json --form --verify=no post https://localhost:8080/login name=demo password=1234567890
POST /login HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 29
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:8080
User-Agent: HTTPie/2.2.0name=demo&password=1234567890
HTTP/1.1 200 OK
Cache-Control: no-cache="Set-Cookie"
Content-Length: 0
Date: Wed, 16 Sep 2020 08:18:19 GMT
Set-Cookie: session=IRygA46_XXlrTaqETg_eNhVoG6bfFKlWQdC9ATAsrPM; Path=/; Expires=Thu, 17 Sep 2020 08:18:20 GMT; Max-Age=86400; HttpOnly; Secure; SameSite=Lax
Vary: Cookiehttp -v --session=./session.json --verify=no https://localhost:8080/check
GET /check HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: session=IRygA46_XXlrTaqETg_eNhVoG6bfFKlWQdC9ATAsrPM
Host: localhost:8080
User-Agent: HTTPie/2.2.0HTTP/1.1 200 OK
Content-Length: 31
Content-Type: text/plain; charset=utf-8
Date: Wed, 16 Sep 2020 08:18:19 GMT{
"Name": "demo",
"Password": null
}http -v --session=./session.json --form --verify=no post https://localhost:8080/logout
POST /logout HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 0
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Cookie: session=IRygA46_XXlrTaqETg_eNhVoG6bfFKlWQdC9ATAsrPM
Host: localhost:8080
User-Agent: HTTPie/2.2.0HTTP/1.1 200 OK
Cache-Control: no-cache="Set-Cookie"
Content-Length: 0
Date: Wed, 16 Sep 2020 08:18:20 GMT
Set-Cookie: session=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; HttpOnly; Secure; SameSite=Lax
Vary: Cookiehttp -v --session=./session.json --verify=no https://localhost:8080/check
GET /check HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/2.2.0HTTP/1.1 401 Unauthorized
Content-Length: 27
Content-Type: text/plain; charset=utf-8
Date: Wed, 16 Sep 2020 08:18:20 GMT
X-Content-Type-Options: nosniffunauthorized, please login
```