Skip to content

Commit b7c04c5

Browse files
committed
chore: add revoke token example
1 parent b8f3678 commit b7c04c5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

examples/all.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ func main() {
1717

1818
g.UserCallback(func(t *goic.Token, u *goic.User, w http.ResponseWriter, r *http.Request) {
1919
log.Printf("token: %v\nuser: %v\n", t, u)
20-
uri := "https://localhost/auth/signout?p=" + t.Provider + "&t=" + t.AccessToken
21-
uri = fmt.Sprintf(`, click <a href="%s">here</a> to signout (some provider may not support it)`, uri)
20+
uri1 := "https://localhost/auth/signout?p=" + t.Provider + "&t=" + t.AccessToken
21+
uri1 = fmt.Sprintf(`,<br><br>click <a href="%s" target="_blank">here</a> to signout (some provider may not support it)`, uri1)
22+
uri2 := "https://localhost/auth/revoke?p=" + t.Provider + "&t=" + t.AccessToken
23+
uri2 = fmt.Sprintf(`,<br><br>click <a href="%s" target="_blank">here</a> to revoke (some provider may not support it)`, uri2)
24+
2225
w.Header().Set("Content-Type", "text/html; charset=utf-8")
23-
_, _ = w.Write([]byte("All good, check backend console" + uri))
26+
_, _ = w.Write([]byte("All good, check backend console" + uri1 + uri2))
2427
})
2528

2629
addr := "localhost:443"
@@ -43,5 +46,16 @@ func main() {
4346
}
4447
})
4548

49+
// Revoke Handler
50+
http.HandleFunc("/auth/revoke/", func(w http.ResponseWriter, r *http.Request) {
51+
q := r.URL.Query()
52+
tok := &goic.Token{Provider: q.Get("p"), AccessToken: q.Get("t")}
53+
if err := g.RevokeToken(tok); err != nil {
54+
http.Error(w, "Can't revoke: "+err.Error(), http.StatusInternalServerError)
55+
return
56+
}
57+
_, _ = w.Write([]byte("Revoked token successfully"))
58+
})
59+
4660
log.Fatal(http.ListenAndServeTLS(addr, "server.crt", "server.key", nil))
4761
}

0 commit comments

Comments
 (0)