From 4d7abae181ad322b613883e6efbdb07a860783a1 Mon Sep 17 00:00:00 2001 From: Abilio Esteves Date: Thu, 16 Jan 2020 12:06:42 -0300 Subject: [PATCH] Issue#24 (#25) * fixed issue#24 * improve documenatation --- README.md | 10 ++++++++-- client/client.go | 11 ++++++----- docker-compose.yml | 33 ++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 41e5ea3..3399edc 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,16 @@ if err == nil { ## Use as a CLI utility -The following command should get you started: +Run the dependencies: ```bash -./whisper-client --client-id teste --client-secret teste123 --whisper-url http://localhost:7070/ --redirect-uris http://redirect1,http://redirect2 --log-level debug --scopes test1,test2 > token.json +docker-compose up -d +``` + +Wait a few seconds to stabilize and then: + +```bash +./whisper-client --client-id teste --client-secret teste123 --whisper-url http://localhost:7070/ --login-redirect-uri http://test.com/login --logout-redirect-uri http://test.com/logout --log-level debug --scopes offline,openid,test1,test2 > token.json ``` The command above will store the generated token as a file called `token.json`. diff --git a/client/client.go b/client/client.go index 281af54..b506e77 100644 --- a/client/client.go +++ b/client/client.go @@ -5,15 +5,16 @@ import ( "context" "crypto/tls" "encoding/json" - "github.com/labbsr0x/goh/gohclient" - "github.com/labbsr0x/whisper-client/misc" - "github.com/sirupsen/logrus" - "golang.org/x/oauth2/clientcredentials" "net/http" "net/url" "reflect" "strings" + "github.com/labbsr0x/goh/gohclient" + "github.com/labbsr0x/whisper-client/misc" + "github.com/sirupsen/logrus" + "golang.org/x/oauth2/clientcredentials" + "github.com/gorilla/mux" "github.com/labbsr0x/goh/gohtypes" @@ -121,7 +122,7 @@ func (client *WhisperClient) IntrospectToken(token string) (result Token, err er httpClient.ContentType = "application/x-www-form-urlencoded" httpClient.Accept = "application/json" - payload := url.Values{"token": []string{token}, "scopes": client.hc.scopes} + payload := url.Values{"token": []string{token}, "scopes": []string{strings.Join(client.hc.scopes, " ")}} payloadData := bytes.NewBufferString(payload.Encode()).Bytes() logrus.Debugf("IntrospectToken - POST payload: '%v'", payloadData) diff --git a/docker-compose.yml b/docker-compose.yml index 570dec8..2f99480 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,27 @@ version: '3.5' services: - whisper-client: + + whisper: build: . - image: labbsr0x/whisper-client:latest + image: labbsr0x/whisper:latest depends_on: + - mysqld-whisper - hydra - command: - /whisper-client --client-id teste --client-secret teste123 --hydra-admin-url http://hydra:4445/ --hydra-public-url http://hydra:4444/ --redirect-uris http://test.com,http://test1.com --log-level debug --scopes test1,test2 > token.json + ports: + - "7070:7070" + environment: + - WHISPER_PORT=7070 + - WHISPER_LOG_LEVEL=debug + - WHISPER_HYDRA_ADMIN_URL=http://hydra:4445/ + - WHISPER_HYDRA_PUBLIC_URL=http://hydra:4444/ + - WHISPER_SECRET_KEY=uhSunsodnsuBsdjsbds + - WHISPER_DATABASE_URL=mysql://root:secret@tcp(mysqld-whisper:3306)/whisper?charset=utf8mb4&parseTime=True&loc=Local + - WHISPER_MAIL_USER=628ecbe7f53ac2 + - WHISPER_MAIL_PASSWORD=457cd26e7890c5 + - WHISPER_MAIL_HOST=smtp.mailtrap.io + - WHISPER_MAIL_PORT=2525 + - WHISPER_PUBLIC_URL=http://localhost:7070 restart: on-failure hydra-migrate: @@ -50,7 +64,16 @@ services: mysqld: image: mysql:5.7 ports: - - "3306:3306" + - 3306 environment: - MYSQL_ROOT_PASSWORD=secret - MYSQL_DATABASE=hydra + + mysqld-whisper: + image: mysql:5.7 + ports: + - 3306 + environment: + - MYSQL_ROOT_PASSWORD=secret + - MYSQL_DATABASE=whisper +