Add ability to set custom token prefix

This commit is contained in:
Kalle Carlbark 2021-11-27 13:10:56 +01:00
parent e23a54368e
commit b054d32835
No known key found for this signature in database

View file

@ -86,6 +86,9 @@ type Client struct {
// Token is set for authentication of the API // Token is set for authentication of the API
Token string Token string
// TokenPrefix is optional to set token prefix other than "Token"
TokenPrefix string
// SessionKey is used to read authentication data // SessionKey is used to read authentication data
SessionKey string SessionKey string
@ -282,7 +285,11 @@ func (c *Client) newRequest(ctx context.Context, method, path string, query stri
} }
if c.Token != "" { if c.Token != "" {
req.Header.Add("Authorization", "Bearer "+c.Token) req.Header.Add("Authorization", "Token "+c.Token)
}
if c.Token != "" && c.TokenPrefix != "" {
req.Header.Add("Authorization", c.TokenPrefix+" "+c.Token)
} }
if c.SessionKey != "" { if c.SessionKey != "" {