From 9ab5a7996247c98ed6267b638e1b313e7c4eb8ff Mon Sep 17 00:00:00 2001 From: enahum Date: Tue, 23 Aug 2016 19:06:17 -0300 Subject: PLT-3745 - Deauthorize OAuth Apps (#3852) * Deauthorize OAuth APIs * Deautorize OAuth Apps Account Settings * Fix typo in client method * Fix issues found by PM * Show help text only when there is at least one authorized app --- store/sql_oauth_store.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'store/sql_oauth_store.go') diff --git a/store/sql_oauth_store.go b/store/sql_oauth_store.go index 6db54bd4a..0ee9f1ad1 100644 --- a/store/sql_oauth_store.go +++ b/store/sql_oauth_store.go @@ -211,6 +211,29 @@ func (as SqlOAuthStore) GetApps() StoreChannel { return storeChannel } +func (as SqlOAuthStore) GetAuthorizedApps(userId string) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var apps []*model.OAuthApp + + if _, err := as.GetReplica().Select(&apps, + `SELECT o.* FROM OAuthApps AS o INNER JOIN + Preferences AS p ON p.Name=o.Id AND p.UserId=:UserId`, map[string]interface{}{"UserId": userId}); err != nil { + result.Err = model.NewLocAppError("SqlOAuthStore.GetAuthorizedApps", "store.sql_oauth.get_apps.find.app_error", nil, "err="+err.Error()) + } + + result.Data = apps + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (as SqlOAuthStore) DeleteApp(id string) StoreChannel { storeChannel := make(StoreChannel) @@ -294,6 +317,33 @@ func (as SqlOAuthStore) GetAccessData(token string) StoreChannel { return storeChannel } +func (as SqlOAuthStore) GetAccessDataByUserForApp(userId, clientId string) StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var accessData []*model.AccessData + + if _, err := as.GetReplica().Select(&accessData, + "SELECT * FROM OAuthAccessData WHERE UserId = :UserId AND ClientId = :ClientId", + map[string]interface{}{"UserId": userId, "ClientId": clientId}); err != nil { + result.Err = model.NewLocAppError("SqlOAuthStore.GetAccessDataByUserForApp", + "store.sql_oauth.get_access_data_by_user_for_app.app_error", nil, + "user_id="+userId+" client_id="+clientId) + } else { + result.Data = accessData + } + + storeChannel <- result + close(storeChannel) + + }() + + return storeChannel +} + func (as SqlOAuthStore) GetAccessDataByRefreshToken(token string) StoreChannel { storeChannel := make(StoreChannel) -- cgit v1.2.3-1-g7c22