@@ -3,23 +3,30 @@ package main
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
7+ "io"
68 "log"
79 "net/http"
810
911 "golang.org/x/oauth2"
1012)
1113
14+ const (
15+ authServerURL = "http://localhost:9096"
16+ )
17+
1218var (
1319 config = oauth2.Config {
1420 ClientID : "222222" ,
1521 ClientSecret : "22222222" ,
1622 Scopes : []string {"all" },
1723 RedirectURL : "http://localhost:9094/oauth2" ,
1824 Endpoint : oauth2.Endpoint {
19- AuthURL : "http://localhost:9096 /authorize" ,
20- TokenURL : "http://localhost:9096 /token" ,
25+ AuthURL : authServerURL + " /authorize" ,
26+ TokenURL : authServerURL + " /token" ,
2127 },
2228 }
29+ globalToken * oauth2.Token // Non-concurrent security
2330)
2431
2532func main () {
@@ -45,9 +52,27 @@ func main() {
4552 http .Error (w , err .Error (), http .StatusInternalServerError )
4653 return
4754 }
55+ globalToken = token
56+
4857 e := json .NewEncoder (w )
4958 e .SetIndent ("" , " " )
50- e .Encode (* token )
59+ e .Encode (token )
60+ })
61+
62+ http .HandleFunc ("/try" , func (w http.ResponseWriter , r * http.Request ) {
63+ if globalToken == nil {
64+ http .Redirect (w , r , "/" , http .StatusFound )
65+ return
66+ }
67+
68+ resp , err := http .Get (fmt .Sprintf ("%s/test?access_token=%s" , authServerURL , globalToken .AccessToken ))
69+ if err != nil {
70+ http .Error (w , err .Error (), http .StatusBadRequest )
71+ return
72+ }
73+ defer resp .Body .Close ()
74+
75+ io .Copy (w , resp .Body )
5176 })
5277
5378 log .Println ("Client is running at 9094 port." )
0 commit comments