Created
January 19, 2024 03:41
-
-
Save hackerzhut/48a145800d42a8755fedac840b53ebae to your computer and use it in GitHub Desktop.
OIDC Token Validation Demo - Azure AD
This file contains hidden or 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
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "github.com/coreos/go-oidc/v3/oidc" | |
| ) | |
| type ( | |
| OIDCConfig struct { | |
| ClientID string `json:"clientId" validate:"required"` | |
| IssuerURL string `json:"issuerURL" validate:"required"` | |
| JwksURL string `json:"jwksURL" validate:"required"` | |
| } | |
| ) | |
| var ( | |
| accessToken = "" | |
| ) | |
| func main() { | |
| cfg := &OIDCConfig{ | |
| ClientID: "", | |
| IssuerURL: "https://login.microsoftonline.com/<your-id>/v2.0", | |
| JwksURL: "https://login.microsoftonline.com/<your-id>/discovery/v2.0/keys", | |
| } | |
| keySet := oidc.NewRemoteKeySet(context.Background(), cfg.JwksURL) | |
| verifier := oidc.NewVerifier(cfg.IssuerURL, keySet, &oidc.Config{ | |
| ClientID: cfg.ClientID, | |
| SkipIssuerCheck: true, | |
| }) | |
| token, err := verifier.Verify(context.Background(), accessToken) | |
| if err != nil || token == nil { | |
| fmt.Println(err) | |
| return | |
| } | |
| fmt.Println("VALID TOKEN: ", token) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment