MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / HandleLogout

Method HandleLogout

pkg/web/oauthclient/logout.go:96–129  ·  view source on GitHub ↗

HandleLogout invalidates the user's authorization, removes the auth cookie and may provide a URL to logout of the OAuth provider as well.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

94// HandleLogout invalidates the user's authorization, removes the auth
95// cookie and may provide a URL to logout of the OAuth provider as well.
96func (oc *OAuthClient) HandleLogout(w http.ResponseWriter, r *http.Request) {
97 value, err := oc.getAuthCookie(w, r)
98 if err != nil {
99 webhandlers.Error(w, r, err)
100 return
101 }
102 oc.removeAuthCookie(w, r)
103
104 token, err := oc.Token(r.Context(), &oauth2.Token{
105 AccessToken: value.AccessToken,
106 RefreshToken: value.RefreshToken,
107 Expiry: time.Now(),
108 })
109 if err != nil {
110 webhandlers.Error(w, r, err)
111 return
112 }
113
114 logoutURL, err := oc.Logout(r.Context(), token)
115 if err != nil {
116 webhandlers.Error(w, r, err)
117 return
118 }
119
120 if logoutURL != "" {
121 webhandlers.JSON(w, r, struct {
122 OpLogoutURI string `json:"op_logout_uri"`
123 }{
124 OpLogoutURI: logoutURL,
125 })
126 } else {
127 w.WriteHeader(http.StatusNoContent)
128 }
129}

Callers

nothing calls this directly

Calls 8

getAuthCookieMethod · 0.95
removeAuthCookieMethod · 0.95
TokenMethod · 0.95
LogoutMethod · 0.95
ErrorFunction · 0.92
JSONFunction · 0.92
ContextMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected