-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Authorization option for eth1 readiness/liveness checks (#3)
- Loading branch information
Showing
6 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package clients | ||
|
||
import ( | ||
"encoding/hex" | ||
"strings" | ||
"time" | ||
|
||
"github.com/golang-jwt/jwt/v4" | ||
) | ||
|
||
type AuthorizationMethod string | ||
|
||
const ( | ||
None AuthorizationMethod = "bearer" | ||
// Bearer Basic AuthorizationMethod = "basic" | ||
Bearer AuthorizationMethod = "bearer" | ||
) | ||
|
||
func CreateJWTAuthToken(jwtSecret string) (string, error) { | ||
secret, err := hex.DecodeString(strings.TrimSpace(jwtSecret)) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// TODO: caching strategy | ||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.RegisteredClaims{ | ||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), | ||
IssuedAt: jwt.NewNumericDate(time.Now()), | ||
NotBefore: jwt.NewNumericDate(time.Now()), | ||
}) | ||
tokenString, err := token.SignedString(secret) | ||
return tokenString, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters