Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
cbaa5d08
Commit
cbaa5d08
authored
2 years ago
by
Jano Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
Add new auth package for bob API keys, and move oauth package to oauth folder
parent
542e4c81
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
auth/api_key.go
+30
-0
30 additions, 0 deletions
auth/api_key.go
oauth/oauth.go
+0
-0
0 additions, 0 deletions
oauth/oauth.go
with
30 additions
and
0 deletions
auth/api_key.go
0 → 100644
+
30
−
0
View file @
cbaa5d08
package
auth
import
(
"github.com/google/uuid"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils"
"strings"
)
// GenerateNewApiKey generates a 32 character API key. If the build environment is dev or stage the key will start with
// "dev_" or "stage_" respectively.
func
GenerateNewApiKey
()
string
{
uniqueKey
:=
uuid
.
New
()
.
String
()
uniqueKey
=
strings
.
ReplaceAll
(
uniqueKey
,
"-"
,
""
)
env
:=
utils
.
GetEnv
(
"ENVIRONMENT"
,
""
)
if
env
==
"dev"
||
env
==
"stage"
{
uniqueKey
=
env
+
"_"
+
uniqueKey
}
return
uniqueKey
}
// GetApiKeyFromHeaders checks if a bearer token is passed as part of the Authorization header and returns that key
func
GetApiKeyFromHeaders
(
headers
map
[
string
]
string
)
string
{
key
:=
headers
[
"Authorization"
]
if
strings
.
HasPrefix
(
strings
.
ToLower
(
key
),
"bearer "
)
{
return
strings
.
TrimPrefix
(
strings
.
ToLower
(
key
),
"bearer"
)
}
return
""
}
This diff is collapsed.
Click to expand it.
auth/oauth.go
→
o
auth/oauth.go
+
0
−
0
View file @
cbaa5d08
File moved
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment