Skip to content

Commit 80805e2

Browse files
author
karlTGA
authored
Merge pull request #13 from Booyaabes/master
Add option to define file path containing client secret
2 parents 8f07ab2 + e4b5edb commit 80805e2

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ We use Keycloak and there you can customize your userinfo.
2323

2424
Configuration options are listed below:
2525

26-
| Options | Description | Mandatory |
27-
|----------------------|-----------------------------------------------------------------------------------------------------|:---------:|
28-
| oauth_client_id | Oauth2 Client id. | Y |
29-
| oauth_client_secret | Oauth2 Client secret. | Y |
30-
| oauth_token_url | `token` endpoint url of the Oauth2 server. | Y |
31-
| oauth_userinfo_url | `userinfo` endpoint url of the Oauth2 server. | Y |
32-
| oauth_cache_duration | Cache duration (in seconds) before the plugin request user info from Oauth2 server. `0` by default. | N |
33-
| oauth_scopes | Comma separated list of requested scopes. No scope by default. | N |
26+
| Options | Description | Mandatory |
27+
|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------:|
28+
| `oauth_client_id` | Oauth2 Client id. | Y |
29+
| `oauth_client_secret` | Oauth2 Client secret. Either `oauth_client_secret` or `oauth_client_secret_file` must be set. If both are set, `oauth_client_secret_file` is used. | N |
30+
| `oauth_client_secret_file` | File containing Oauth2 Client secret. Either `oauth_client_secret` or `oauth_client_secret_file` must be set. If both are set, `oauth_client_secret_file` is used. | N |
31+
| `oauth_token_url` | `token` endpoint url of the Oauth2 server. | Y |
32+
| `oauth_userinfo_url` | `userinfo` endpoint url of the Oauth2 server. | Y |
33+
| `oauth_cache_duration` | Cache duration (in seconds) before the plugin request user info from Oauth2 server. `0` by default. | N |
34+
| `oauth_scopes` | Comma separated list of requested scopes. No scope by default. | N |
3435

3536
## How to test
3637

src/main.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"encoding/json"
6+
"io/ioutil"
67
"mosquitto-go-auth-oauth2/topics"
78
"net/http"
89
"strconv"
@@ -186,9 +187,22 @@ func Init(authOpts map[string]string, logLevel log.Level) error {
186187
if !ok {
187188
log.Panic("Got no clientId for oauth plugin.")
188189
}
189-
clientSecret, ok := authOpts["oauth_client_secret"]
190+
clientSecretFile, ok := authOpts["oauth_client_secret_file"]
190191
if !ok {
191-
log.Panic("Got no client secret for oauth plugin.")
192+
log.Info("Got no client secret file for oauth plugin.")
193+
}
194+
var clientSecret string
195+
if clientSecretFile == "" {
196+
clientSecret, ok = authOpts["oauth_client_secret"]
197+
if !ok {
198+
log.Panic("Got no client secret for oauth plugin.")
199+
}
200+
} else {
201+
content, err := ioutil.ReadFile(clientSecretFile)
202+
if err != nil {
203+
log.Panic("Client secret file for oauth plugin doesn't exist.")
204+
}
205+
clientSecret = string(content)
192206
}
193207
tokenURL, ok := authOpts["oauth_token_url"]
194208
if !ok {

0 commit comments

Comments
 (0)