Documentation ¶
Overview ¶
This module seeks to have a similarity to that found in Verify the Google ID token on your server side: https://developers.google.com/identity/gsi/web/guides/verify-google-id-token for other languages. It validates if the generated JWT corresponds to Google and also provides the possibility to validate if the user who issued the token is or is not from a specific domain.
This module have two functions:
- Verify(token string, aud string) *TokenInfo
- VerifyDomain(token string, aud string, domain string) *TokenInfo
The first function only validates if the token is from Google and the second function validates if the token is from Google and if the user is from the specified domain.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TokenInfo ¶
type TokenInfo struct { Sub string `json:"sub"` Email string `json:"email"` AtHash string `json:"at_hash"` Aud string `json:"aud"` EmailVerified bool `json:"email_verified"` Name string `json:"name"` GivenName string `json:"given_name"` FamilyName string `json:"family_name"` Picture string `json:"picture"` Local string `json:"locale"` Iss string `json:"iss"` Azp string `json:"azp"` Iat int64 `json:"iat"` Exp int64 `json:"exp"` }
TokenInfo is the struct that contains the information of the token
func Verify ¶
Verify verifies the token and returns the token info if the token is valid. Otherwise, it returns nil.
Example ¶
package main import ( "fmt" "github.com/croonix/gTokenVerifier" ) func main() { var ( authTokenTest = "" audTest = "" ) tokenInfo := gTokenVerifier.Verify(authTokenTest, audTest) if tokenInfo != nil { fmt.Println(tokenInfo) } }
Output:
func VerifyByDomain ¶ added in v1.0.0
VerifyByDomain verifies the token and checks if the user in the JWT is from the specified domain. Otherwise, it returns nil.
Example ¶
package main import ( "fmt" "github.com/croonix/gTokenVerifier" ) func main() { var ( authTokenTest = "" audTest = "" audDomainTest = "" ) tokenInfo := gTokenVerifier.VerifyByDomain(authTokenTest, audTest, audDomainTest) if tokenInfo != nil { fmt.Println(tokenInfo) } }
Output: