Skip to content

Commit c7ee172

Browse files
committed
chore: signout example
1 parent 25dde2a commit c7ee172

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ when GOIC has new features.
149149
### Signing out
150150

151151
For signing out you need to manually invoke `g.SignOut()` from within http context. See the [API](#signout) below.
152+
There is also a working [example](./examples/all.go). Note that not all Providers support signing out.
152153

153154
---
154155
## GOIC API

examples/all.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56
"net/http"
67
"os"
@@ -16,7 +17,10 @@ func main() {
1617

1718
g.UserCallback(func(t *goic.Token, u *goic.User, w http.ResponseWriter, r *http.Request) {
1819
log.Printf("token: %v\nuser: %v\n", t, u)
19-
_, _ = w.Write([]byte("All good, check backend console"))
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)
22+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
23+
_, _ = w.Write([]byte("All good, check backend console" + uri))
2024
})
2125

2226
addr := "localhost:443"
@@ -29,5 +33,15 @@ func main() {
2933
log.Printf(" https://localhost/auth/o8/%s\n", v)
3034
}
3135
http.HandleFunc("/", g.MiddlewareFunc(handler))
36+
37+
// SignOut handler
38+
http.HandleFunc("/auth/signout/", func(w http.ResponseWriter, r *http.Request) {
39+
q := r.URL.Query()
40+
tok := &goic.Token{Provider: q.Get("p"), AccessToken: q.Get("t")}
41+
if err := g.SignOut(tok, "", w, r); err != nil {
42+
http.Error(w, "can't signout: "+err.Error(), http.StatusInternalServerError)
43+
}
44+
})
45+
3246
log.Fatal(http.ListenAndServeTLS(addr, "server.crt", "server.key", nil))
3347
}

0 commit comments

Comments
 (0)