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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
4d617af2
Commit
4d617af2
authored
2 years ago
by
Johan de Klerk
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of gitlab.bob.co.za:bob-public-utils/bobgroup-go-utils
parents
b54ec0ec
3df5f6c6
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
auth/session.go
+6
-4
6 additions, 4 deletions
auth/session.go
cognito/cognito.go
+12
-0
12 additions, 0 deletions
cognito/cognito.go
errors/errors.go
+12
-0
12 additions, 0 deletions
errors/errors.go
with
30 additions
and
4 deletions
auth/session.go
+
6
−
4
View file @
4d617af2
...
@@ -51,17 +51,19 @@ func GetSignedSessionTokenString(request events.APIGatewayProxyRequest, secretKe
...
@@ -51,17 +51,19 @@ func GetSignedSessionTokenString(request events.APIGatewayProxyRequest, secretKe
// ValidateJWTWithSessionTokens attempts to validate the JWT string by signing each session token using the secret, and
// ValidateJWTWithSessionTokens attempts to validate the JWT string by signing each session token using the secret, and
// using the resulting signed session token to validate the JWT. If the JWT can be validated using a session token, the
// using the resulting signed session token to validate the JWT. If the JWT can be validated using a session token, the
// JsonWebToken is returned, otherwise nil is returned.
// JsonWebToken is returned, otherwise nil is returned.
If the JWT is expired, nil is returned along with the session token.
func
ValidateJWTWithSessionTokens
(
jsonWebTokenString
string
,
secretKey
string
,
sessionTokens
[]
string
)
*
JsonWebToken
{
func
ValidateJWTWithSessionTokens
(
jsonWebTokenString
string
,
secretKey
string
,
sessionTokens
[]
string
)
(
validJsonWebToken
*
JsonWebToken
,
expiredSessionToken
*
string
)
{
// Test each session token to find one that is valid
// Test each session token to find one that is valid
for
_
,
sessionToken
:=
range
sessionTokens
{
for
_
,
sessionToken
:=
range
sessionTokens
{
jsonWebToken
,
err
:=
ValidateJWTWithSessionToken
(
jsonWebTokenString
,
secretKey
,
sessionToken
)
jsonWebToken
,
err
:=
ValidateJWTWithSessionToken
(
jsonWebTokenString
,
secretKey
,
sessionToken
)
if
err
==
nil
{
if
err
==
nil
{
return
&
jsonWebToken
return
&
jsonWebToken
,
nil
}
else
if
err
.
Error
()
==
"token has expired"
{
return
nil
,
&
sessionToken
}
}
}
}
return
nil
return
nil
,
nil
}
}
// FindAndRemoveCurrentSessionToken attempts to validate the JWT string by signing each session token using the secret,
// FindAndRemoveCurrentSessionToken attempts to validate the JWT string by signing each session token using the secret,
...
...
This diff is collapsed.
Click to expand it.
cognito/cognito.go
+
12
−
0
View file @
4d617af2
...
@@ -90,6 +90,18 @@ func SetUserPassword(pool string, username string, password string) (*cognitoide
...
@@ -90,6 +90,18 @@ func SetUserPassword(pool string, username string, password string) (*cognitoide
return
output
,
err
return
output
,
err
}
}
func
ConfirmPasswordReset
(
appClientID
string
,
username
string
,
password
string
,
confirmationCode
string
)
(
*
cognitoidentityprovider
.
ConfirmForgotPasswordOutput
,
error
)
{
input
:=
cognitoidentityprovider
.
ConfirmForgotPasswordInput
{
ClientId
:
&
appClientID
,
ConfirmationCode
:
&
confirmationCode
,
Password
:
&
password
,
Username
:
&
username
,
}
output
,
err
:=
CognitoService
.
ConfirmForgotPassword
(
&
input
)
logs
.
Info
(
"output"
,
output
)
return
output
,
err
}
// FOR API LOGS
// FOR API LOGS
func
DetermineAuthType
(
identity
events
.
APIGatewayRequestIdentity
)
*
string
{
func
DetermineAuthType
(
identity
events
.
APIGatewayRequestIdentity
)
*
string
{
...
...
This diff is collapsed.
Click to expand it.
errors/errors.go
+
12
−
0
View file @
4d617af2
...
@@ -2,6 +2,7 @@ package errors
...
@@ -2,6 +2,7 @@ package errors
import
(
import
(
"fmt"
"fmt"
"github.com/aws/aws-sdk-go/aws/awserr"
pkg_errors
"github.com/pkg/errors"
pkg_errors
"github.com/pkg/errors"
)
)
...
@@ -111,6 +112,17 @@ func HTTPWithError(code int, err error) error {
...
@@ -111,6 +112,17 @@ func HTTPWithError(code int, err error) error {
return
wrappedErr
return
wrappedErr
}
}
func
AWSErrorWithoutExceptionCode
(
err
error
)
error
{
if
err
==
nil
{
return
nil
}
if
awsError
,
ok
:=
err
.
(
awserr
.
Error
);
ok
{
return
Error
(
awsError
.
Message
())
}
return
err
}
type
Description
struct
{
type
Description
struct
{
Message
string
`json:"error"`
Message
string
`json:"error"`
Source
*
CallerInfo
`json:"source,omitempty"`
Source
*
CallerInfo
`json:"source,omitempty"`
...
...
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