1
1
package main
2
2
3
3
import (
4
+ "fmt"
4
5
"log"
5
6
"net/http"
6
7
"os"
@@ -16,7 +17,10 @@ func main() {
16
17
17
18
g .UserCallback (func (t * goic.Token , u * goic.User , w http.ResponseWriter , r * http.Request ) {
18
19
log .Printf ("token: %v\n user: %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 ))
20
24
})
21
25
22
26
addr := "localhost:443"
@@ -29,5 +33,15 @@ func main() {
29
33
log .Printf (" https://localhost/auth/o8/%s\n " , v )
30
34
}
31
35
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
+
32
46
log .Fatal (http .ListenAndServeTLS (addr , "server.crt" , "server.key" , nil ))
33
47
}
0 commit comments