예제 #1
0
파일: team.go 프로젝트: ZJvandeWeg/platform
func revokeAllSessions(c *Context, w http.ResponseWriter, r *http.Request) {
	props := model.MapFromJson(r.Body)
	id := props["id"]

	if result := <-app.Srv.Store.Session().Get(id); result.Err != nil {
		c.Err = result.Err
		return
	} else {
		session := result.Data.(*model.Session)

		c.LogAudit("revoked_all=" + id)

		if session.IsOAuth {
			if err := app.RevokeAccessToken(session.Token); err != nil {
				c.Err = err
				return
			}
		} else {
			if result := <-app.Srv.Store.Session().Remove(session.Id); result.Err != nil {
				c.Err = result.Err
				return
			} else {
				app.RemoveAllSessionsForUserId(session.UserId)
				w.Write([]byte(model.MapToJson(props)))
				return
			}
		}
	}
}
예제 #2
0
func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
	if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
		c.Err = model.NewLocAppError("deleteOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "")
		c.Err.StatusCode = http.StatusNotImplemented
		return
	}

	params := mux.Vars(r)
	id := params["id"]

	if len(id) == 0 {
		c.SetInvalidParam("deauthorizeOAuthApp", "id")
		return
	}

	// revoke app sessions
	if result := <-app.Srv.Store.OAuth().GetAccessDataByUserForApp(c.Session.UserId, id); result.Err != nil {
		c.Err = result.Err
		return
	} else {
		accessData := result.Data.([]*model.AccessData)

		for _, a := range accessData {
			if err := app.RevokeAccessToken(a.Token); err != nil {
				c.Err = err
				return
			}

			if rad := <-app.Srv.Store.OAuth().RemoveAccessData(a.Token); rad.Err != nil {
				c.Err = rad.Err
				return
			}
		}
	}

	// Deauthorize the app
	if err := (<-app.Srv.Store.Preference().Delete(c.Session.UserId, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, id)).Err; err != nil {
		c.Err = err
		return
	}

	c.LogAudit("success")
	ReturnStatusOK(w)
}