Skip to content
Snippets Groups Projects
Commit 4d617af2 authored by Johan de Klerk's avatar Johan de Klerk
Browse files

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
...@@ -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,
......
...@@ -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 {
......
...@@ -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"`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment