Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

PXP-6814 Expect "bearer" in the auth header #41

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ repos:
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
exclude: vendor/*
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
Expand Down
66 changes: 66 additions & 0 deletions .secrets.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"exclude": {
"files": "vendor/*",
"lines": null
},
"generated_at": "2020-11-12T20:38:16Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
},
{
"name": "ArtifactoryDetector"
},
{
"base64_limit": 4.5,
"name": "Base64HighEntropyString"
},
{
"name": "BasicAuthDetector"
},
{
"name": "CloudantDetector"
},
{
"hex_limit": 3,
"name": "HexHighEntropyString"
},
{
"name": "IbmCloudIamDetector"
},
{
"name": "IbmCosHmacDetector"
},
{
"name": "JwtTokenDetector"
},
{
"keyword_exclude": null,
"name": "KeywordDetector"
},
{
"name": "MailchimpDetector"
},
{
"name": "PrivateKeyDetector"
},
{
"name": "SlackDetector"
},
{
"name": "SoftlayerDetector"
},
{
"name": "StripeDetector"
},
{
"name": "TwilioKeyDetector"
}
],
"results": {},
"version": "0.13.1",
"word_list": {
"file": null,
"hash": null
}
}
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ hit all the Mariner API endpoints.

2. Fetch token using API key
```
echo Authorization: $(curl -d '{"api_key": "<replaceme>", "key_id": "<replaceme>"}' -X POST -H "Content-Type: application/json" https://<replaceme>.planx-pla.net/user/credentials/api/access_token | jq .access_token | sed 's/"//g') > auth
echo Authorization: bearer $(curl -d '{"api_key": "<replaceme>", "key_id": "<replaceme>"}' -X POST -H "Content-Type: application/json" https://<replaceme>.planx-pla.net/user/credentials/api/access_token | jq .access_token | sed 's/"//g') > auth
```

3. POST the workflow request
Expand Down
8 changes: 5 additions & 3 deletions mariner/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,14 @@ func (server *Server) handleAuth(next http.Handler) http.Handler {

// polish this
func authHTTPRequest(r *http.Request) (*AuthHTTPRequest, error) {
token := r.Header.Get(authHeader)
if token == "" {
authHeader := r.Header.Get(authHeader)
if authHeader == "" {
return nil, fmt.Errorf("no token in Authorization header")
}
userJWT := strings.TrimPrefix(authHeader, "Bearer ")
userJWT = strings.TrimPrefix(userJWT, "bearer ")
user := &UserJSON{
Token: token,
Token: userJWT,
}
authRequest := &AuthRequest{
Resource: "/mariner",
Expand Down
9 changes: 8 additions & 1 deletion mariner/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import (
"errors"
"fmt"
"net/http"
"strings"
)

type TokenInfo struct {
UserID string
}

func (server *Server) userID(r *http.Request) (userID string) {
info, err := server.decodeToken(r.Header.Get(authHeader))
authHeader := r.Header.Get(authHeader)
if authHeader == "" {
fmt.Println("no token in Authorization header")
}
userJWT := strings.TrimPrefix(authHeader, "Bearer ")
userJWT = strings.TrimPrefix(userJWT, "bearer ")
info, err := server.decodeToken(userJWT)
if err != nil {
// log error
fmt.Println("error decoding token: ", err)
Expand Down