summaryrefslogtreecommitdiffstats
path: root/api/oauth.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-01-13 15:17:50 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2017-01-13 15:17:50 -0500
commit0e2b321e6f5ab5983bc3428aa455dac7012c36ee (patch)
treec3919a284cf13ddcb66a6f482b1c9bbd9f34fc9b /api/oauth.go
parent97558f6a6ec4c53fa69035fb430ead209d9c222d (diff)
downloadchat-0e2b321e6f5ab5983bc3428aa455dac7012c36ee.tar.gz
chat-0e2b321e6f5ab5983bc3428aa455dac7012c36ee.tar.bz2
chat-0e2b321e6f5ab5983bc3428aa455dac7012c36ee.zip
Refactor and migrate more functions out of api into app package (#5063)
Diffstat (limited to 'api/oauth.go')
-rw-r--r--api/oauth.go34
1 files changed, 6 insertions, 28 deletions
diff --git a/api/oauth.go b/api/oauth.go
index 80daf7415..b378eb2a3 100644
--- a/api/oauth.go
+++ b/api/oauth.go
@@ -250,32 +250,6 @@ func getAuthorizedApps(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
-func RevokeAccessToken(token string) *model.AppError {
-
- session, _ := app.GetSession(token)
- schan := app.Srv.Store.Session().Remove(token)
-
- if result := <-app.Srv.Store.OAuth().GetAccessData(token); result.Err != nil {
- return model.NewLocAppError("RevokeAccessToken", "api.oauth.revoke_access_token.get.app_error", nil, "")
- }
-
- tchan := app.Srv.Store.OAuth().RemoveAccessData(token)
-
- if result := <-tchan; result.Err != nil {
- return model.NewLocAppError("RevokeAccessToken", "api.oauth.revoke_access_token.del_token.app_error", nil, "")
- }
-
- if result := <-schan; result.Err != nil {
- return model.NewLocAppError("RevokeAccessToken", "api.oauth.revoke_access_token.del_session.app_error", nil, "")
- }
-
- if session != nil {
- app.RemoveAllSessionsForUserId(session.UserId)
- }
-
- return nil
-}
-
func GetAuthData(code string) *model.AuthData {
if result := <-app.Srv.Store.OAuth().GetAuthData(code); result.Err != nil {
l4g.Error(utils.T("api.oauth.get_auth_data.find.error"), code)
@@ -311,7 +285,11 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
action := props["action"]
switch action {
case model.OAUTH_ACTION_SIGNUP:
- CreateOAuthUser(c, w, r, service, body, teamId)
+ if user, err := app.CreateOAuthUser(service, body, teamId); err != nil {
+ c.Err = err
+ } else {
+ doLogin(c, w, r, user, "")
+ }
if c.Err == nil {
http.Redirect(w, r, GetProtocol(r)+"://"+r.Host, http.StatusTemporaryRedirect)
}
@@ -931,7 +909,7 @@ func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
accessData := result.Data.([]*model.AccessData)
for _, a := range accessData {
- if err := RevokeAccessToken(a.Token); err != nil {
+ if err := app.RevokeAccessToken(a.Token); err != nil {
c.Err = err
return
}