https://github.com/ma91n/go-swagger-oauth2-security
SAMPLE APP: This repository is sample application intended to try oauth2 authentication using go-swagger with KeyCloak.
https://github.com/ma91n/go-swagger-oauth2-security
Last synced: 3 months ago
JSON representation
SAMPLE APP: This repository is sample application intended to try oauth2 authentication using go-swagger with KeyCloak.
- Host: GitHub
- URL: https://github.com/ma91n/go-swagger-oauth2-security
- Owner: ma91n
- License: apache-2.0
- Created: 2020-07-26T05:42:27.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-27T00:15:17.000Z (almost 5 years ago)
- Last Synced: 2025-01-13T16:17:35.626Z (5 months ago)
- Language: Go
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-swagger-oauth2-security
SAMPLE APP: This repository is sample application intended to try oauth2 authentication using go-swagger with KeyCloak## Abstract
This is POC application that confirm go-swagger server and keycloak authentication workflow.
## Usage
Run KeyCloak Server.
> docker run -d -p 18080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin --name keycloak jboss/keycloak go run main.go
Access localhost:18080 with your browser.
* xxx
* xxx
* xxxRegister Google callback URL
* follow bellow url
* https://github.com/go-swagger/go-swagger/tree/master/examples/oauth2#register-the-callback-urlRun API server.
> set ClientID=
> set ClientSecret=
> go run gen/cmd/hellouah-server/main.go --host 0.0.0.0 --port 8080Send api request.
> curl -i -H 'Authorization: Bearer ya29.a0AfH6SMAijuEYH0qiV-HhyNXl3hHACKwrTbheWCJ2VzDEjVDokCRcJuZ832dC7KKkoxruIsMMDW1I-eb1x2t51G6G9DJWU_mZ2Ir16Uv_LyjFCJC9YvgZ2SK8xK3FVZQ_rrdqzt1uy6hxRCUIS0Xv9_IbKP07EK6gdl4' http://172.30.32.1:8080/v1/hello
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sun, 26 Jul 2020 07:34:28 GMT
Content-Length: 20
{"message":"hello"}Send invalid token.
> curl -i -H 'Authorization: Bearer ya29.111111' http://172.30.32.1:8080/v1/hello
HTTP/1.1 401 Unauthorized
Content-Type: application/json
Date: Sun, 26 Jul 2020 07:35:20 GMT
Content-Length: 38{"code":401,"message":"invalid token"}
## Development Memo
```sh
# Install go-swagger
go get -u github.com/go-swagger/[email protected]# generate file
swagger generate server -a hellouah -A hellouah -P models.Principal --strict-additional-properties -t gen
```