Documentation
¶
Index ¶
- Variables
- func GoKitMiddleware(v verifier) endpoint.Middleware
- func Middleware(v verifier) func(http.Handler) http.Handler
- func RefreshToken(jwt interface{ ... }) http.HandlerFunc
- func RequestAuth(w http.ResponseWriter, r *http.Request)
- func VerifySignature(message, signature, publicKey string) error
- func VerifySignedMessage(jwt interface{ ... }) http.HandlerFunc
- type Claims
- type JWT
- type RefreshTokenPayload
- type RequestAuthHandlePayload
- type TokenResponse
- type VerifySignedMessagePayload
Constants ¶
This section is empty.
Variables ¶
var (
)Predefined errors
var TokenClaimsContextKey = &contextKey{name: "token-claims"}
TokenClaimsContextKey is the key for the token claims in the request context.
Functions ¶
func GoKitMiddleware ¶
func GoKitMiddleware(v verifier) endpoint.Middleware
GoKitMiddleware is a middleware for SolAuth. It will check the context for a valid token and add the claims to the context.
func Middleware ¶
Middleware is a middleware for SolAuth. It will check the request for a valid token and add the claims to the request context.
func RefreshToken ¶
func RefreshToken(jwt interface { RefreshToken(tokenString string) (TokenResponse, error) }, ) http.HandlerFunc
RefreshToken is the handler for the refresh token. It refreshes the access token.
func RequestAuth ¶
func RequestAuth(w http.ResponseWriter, r *http.Request)
RequestAuth is the handler for the request authentication. It gets the wallet address and returns message to sign. The message must be signed by the wallet and sent back to the server. The server will verify the signature and return the result.
func VerifySignature ¶
VerifySignature verifies the signature of the request. This function verifies the signature of the message using the public key of the sender. It returns error if the signature is NOT valid, otherwise nil.
func VerifySignedMessage ¶
func VerifySignedMessage(jwt interface { IssueTokens(walletAddr string) (TokenResponse, error) }, ) http.HandlerFunc
VerifySignedMessage is the handler for the signed message verification. It verifies the signature of the message using the public key of the sender. It returns access token if the signature is valid, otherwise error.
Types ¶
type Claims ¶
type Claims struct { Wallet string `json:"wallet"` jwt.RegisteredClaims }
Claims is the claims for the token.
func GetClaimsFromContext ¶
Get claims from context
func GetClaimsFromRequest ¶
Get claims from request context
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
JWT is the interactor for JWT.
func (*JWT) IssueTokens ¶
func (j *JWT) IssueTokens(walletAddr string) (TokenResponse, error)
IssueToken issues a token for the user. This function generates a token for the user and returns it.
func (*JWT) RefreshToken ¶
func (j *JWT) RefreshToken(tokenString string) (TokenResponse, error)
RefreshToken refreshes the token. This function refreshes the token and returns the new token.
type RefreshTokenPayload ¶
type RefreshTokenPayload struct { // RefreshToken is the refresh token. RefreshToken string `json:"refresh_token"` }
RefreshTokenPayload is the payload for the refresh token.
type RequestAuthHandlePayload ¶
type RequestAuthHandlePayload struct { // PublicKey is the public key of the sender. PublicKey string `json:"public_key"` }
RequestAuthHandlePayload is the payload for the request authentication.
type TokenResponse ¶
type TokenResponse struct { Access string `json:"access_token"` Refresh string `json:"refresh_token"` ExpiresIn int64 `json:"expires_in"` }
TokenResponse is the response for the token request.
type VerifySignedMessagePayload ¶
type VerifySignedMessagePayload struct { // Message is the message that was signed. Message string `json:"message"` // Signature is the signature of the message. Signature string `json:"signature"` // PublicKey is the public key of the sender. PublicKey string `json:"public_key"` }
VerifySignedMessagePayload is the payload for the signed message verification.
func (*VerifySignedMessagePayload) Validate ¶
func (p *VerifySignedMessagePayload) Validate() error
Validate validates the payload.