@@ -29,9 +29,9 @@ type Auth struct {
2929 clientSecret string
3030 // serverURL is the "base" URL that this service is hosted from, e.g. "http://localhost:8000"
3131 serverURL string
32- // authenticateURL is the URL for users to start the OAuth flow and login.
32+ // loginURL is the URL for users to start the OAuth flow and login.
3333 // Commonly, this is set to something like ServerHost+"/auth/login"
34- authenticateURL string
34+ loginURL string
3535 // callbackURL is the URL that users will be redirected to at the end of the OAuth flow.
3636 // Commonly, this is set to something like ServerHost+"/auth/callback"
3737 callbackURL string
@@ -56,14 +56,14 @@ type Claims struct {
5656 UserInfo
5757}
5858
59- func Init (oidcClientID string , oidcClientSecret string , serverURL string , authenticateURL string , callbackURL string , scopes []string ) (Auth , error ) {
59+ func Init (oidcClientID string , oidcClientSecret string , serverURL string , loginURL string , callbackURL string , scopes []string ) (Auth , error ) {
6060 auth := Auth {
61- clientID : oidcClientID ,
62- clientSecret : oidcClientSecret ,
63- serverURL : serverURL ,
64- authenticateURL : authenticateURL ,
65- callbackURL : callbackURL ,
66- ctx : context .Background (),
61+ clientID : oidcClientID ,
62+ clientSecret : oidcClientSecret ,
63+ serverURL : serverURL ,
64+ loginURL : loginURL ,
65+ callbackURL : callbackURL ,
66+ ctx : context .Background (),
6767 }
6868
6969 auth .secure = serverURL [0 :5 ] == "https"
@@ -106,18 +106,18 @@ func (auth *Auth) HandleCallback(c *gin.Context) {
106106 ref , err := c .Cookie ("ref" )
107107 if err != nil {
108108 log .Error ("no callback ref cookie" )
109- c .Redirect (http .StatusFound , auth .authenticateURL )
109+ c .Redirect (http .StatusFound , auth .loginURL )
110110 return
111111 }
112112 state , ok := StateLookup [ref ]
113113 if ! ok {
114114 log .Error ("callback ref not found" )
115- c .Redirect (http .StatusFound , auth .authenticateURL )
115+ c .Redirect (http .StatusFound , auth .loginURL )
116116 return
117117 }
118118 if c .Query ("state" ) != state {
119119 log .Error ("state does not match" )
120- c .Redirect (http .StatusFound , auth .authenticateURL )
120+ c .Redirect (http .StatusFound , auth .loginURL )
121121 return
122122 }
123123
@@ -131,14 +131,19 @@ func (auth *Auth) HandleCallback(c *gin.Context) {
131131 c .Redirect (http .StatusFound , c .Query ("referer" ))
132132}
133133
134+ func (auth * Auth ) HandleLogout (c * gin.Context ) {
135+ c .SetCookie (CookieName , "" , 0 , "" , "" , false , true )
136+ c .Redirect (http .StatusFound , ProviderURI + "/protocol/openid-connect/logout?post_logout_redirect_uri=" + auth .serverURL + "/&client_id=" + auth .clientID + "" )
137+ }
138+
134139// Middleware functions
135140
136141func (auth * Auth ) CookieMiddleware () gin.HandlerFunc {
137142 return func (c * gin.Context ) {
138143 cookie , err := c .Cookie (CookieName )
139144 if err != nil {
140145 log .Error (CookieName , "cookie not found" )
141- c .Redirect (http .StatusFound , auth .authenticateURL + "?referer=" + c .Request .URL .String ())
146+ c .Redirect (http .StatusFound , auth .loginURL + "?referer=" + c .Request .URL .String ())
142147 return
143148 }
144149 err = auth .setGinContext (c , cookie )
0 commit comments