From b054d32835f6ac305b690b805939e218ed48073c Mon Sep 17 00:00:00 2001 From: Kalle Carlbark Date: Sat, 27 Nov 2021 13:10:56 +0100 Subject: [PATCH] Add ability to set custom token prefix --- netbox.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/netbox.go b/netbox.go index f2ba069..7d79744 100644 --- a/netbox.go +++ b/netbox.go @@ -86,6 +86,9 @@ type Client struct { // Token is set for authentication of the API Token string + // TokenPrefix is optional to set token prefix other than "Token" + TokenPrefix string + // SessionKey is used to read authentication data SessionKey string @@ -282,7 +285,11 @@ func (c *Client) newRequest(ctx context.Context, method, path string, query stri } 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 != "" {