Skip to content

Commit

Permalink
Fix issue with privatekey
Browse files Browse the repository at this point in the history
- private key value was being used as if it were a path after
refactoring to config pattern. The code now accepts the key
value and uses it as is. Tested live.

Signed-off-by: Alex Ellis <[email protected]>
  • Loading branch information
alexellis committed Oct 27, 2018
1 parent 784b916 commit d2eb3f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 4 additions & 7 deletions auth/jwt_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import (
)

// GetSignedJwtToken get a tokens signed with private key
func GetSignedJwtToken(appID string, privateKeyPath string) (string, error) {
func GetSignedJwtToken(appID string, privateKey string) (string, error) {

keyBytes, err := ioutil.ReadFile(privateKeyPath)
if err != nil {
return "", fmt.Errorf("unable to read private key path: %s, error: %s", privateKeyPath, err)
}
keyBytes := []byte(privateKey)

key, keyErr := jwt.ParseRSAPrivateKeyFromPEM(keyBytes)
if keyErr != nil {
Expand Down Expand Up @@ -50,8 +47,8 @@ type JWTAuth struct {
}

// MakeAccessTokenForInstallation makes an access token for an installation / private key
func MakeAccessTokenForInstallation(appID string, installation int, privateKeyPath string) (string, error) {
signed, err := GetSignedJwtToken(appID, privateKeyPath)
func MakeAccessTokenForInstallation(appID string, installation int, privateKey string) (string, error) {
signed, err := GetSignedJwtToken(appID, privateKey)

if err == nil {
c := http.Client{}
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ func NewConfig() (Config, error) {

if val, ok := os.LookupEnv("application_id"); ok && len(val) > 0 {
config.ApplicationID = val
} else {
return config, fmt.Errorf("application_id must be given")
}

// debug, _ := json.Marshal(config)
// fmt.Printf("Config:\n%s\n", debug)

return config, nil
}

Expand Down
2 changes: 1 addition & 1 deletion derek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ provider:
functions:
derek:
handler: ./
image: alexellis/derek:0.6.3-rc1
image: alexellis/derek:0.6.3-rc2
lang: dockerfile
environment:
debug: true
Expand Down

0 comments on commit d2eb3f9

Please sign in to comment.