File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -44,4 +44,17 @@ Open the browser [http://localhost:9094/try](http://localhost:9094/try)
4444 "expires_in": 7195,
4545 "user_id": "000000"
4646}
47+ ```
48+
49+ ## Refresh token
50+
51+ Open the browser [ http://localhost:9094/refresh ] ( http://localhost:9094/refresh )
52+
53+ ```
54+ {
55+ "access_token": "0IIL4_AJN2-SR0JEYZVQWG",
56+ "token_type": "Bearer",
57+ "refresh_token": "AG6-63MLXUEFUV2Q_BLYIW",
58+ "expiry": "2019-01-09T23:03:16.374062+08:00"
59+ }
4760```
Original file line number Diff line number Diff line change 77 "io"
88 "log"
99 "net/http"
10+ "time"
1011
1112 "golang.org/x/oauth2"
1213)
@@ -59,6 +60,25 @@ func main() {
5960 e .Encode (token )
6061 })
6162
63+ http .HandleFunc ("/refresh" , func (w http.ResponseWriter , r * http.Request ) {
64+ if globalToken == nil {
65+ http .Redirect (w , r , "/" , http .StatusFound )
66+ return
67+ }
68+
69+ globalToken .Expiry = time .Now ()
70+ token , err := config .TokenSource (context .Background (), globalToken ).Token ()
71+ if err != nil {
72+ http .Error (w , err .Error (), http .StatusInternalServerError )
73+ return
74+ }
75+
76+ globalToken = token
77+ e := json .NewEncoder (w )
78+ e .SetIndent ("" , " " )
79+ e .Encode (token )
80+ })
81+
6282 http .HandleFunc ("/try" , func (w http.ResponseWriter , r * http.Request ) {
6383 if globalToken == nil {
6484 http .Redirect (w , r , "/" , http .StatusFound )
Original file line number Diff line number Diff line change 3535 DefaultImplicitTokenCfg = & Config {AccessTokenExp : time .Hour * 1 }
3636 DefaultPasswordTokenCfg = & Config {AccessTokenExp : time .Hour * 2 , RefreshTokenExp : time .Hour * 24 * 7 , IsGenerateRefresh : true }
3737 DefaultClientTokenCfg = & Config {AccessTokenExp : time .Hour * 2 }
38- DefaultRefreshTokenCfg = & RefreshingConfig {IsRemoveAccess : true , IsRemoveRefreshing : true }
38+ DefaultRefreshTokenCfg = & RefreshingConfig {IsGenerateRefresh : true , IsRemoveAccess : true , IsRemoveRefreshing : true }
3939)
You can’t perform that action at this time.
0 commit comments