diff options
Diffstat (limited to 'store/sql_oauth_store.go')
-rw-r--r-- | store/sql_oauth_store.go | 50 |
1 files changed, 50 insertions, 0 deletions
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) |