-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathqueries.go
154 lines (131 loc) · 8.29 KB
/
queries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package mysqldb
/*
Copyright (C) 2019 Ulbora Labs LLC. (www.ulboralabs.com)
All rights reserved.
Copyright (C) 2019 Ken Williamson
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const (
oauthTest = "select count(*) from client "
//Client queries
insertClient = "insert into client (secret, name, web_site, email, enabled, paid) values(?, ?, ?, ?, ?, ?)"
updateClient = " UPDATE client SET secret = ?, name = ?, web_site = ?, email = ?, " +
" enabled = ?, paid = ? WHERE client_id = ? "
getClientByID = "SELECT client_id, secret, name, web_site, email, enabled, paid FROM client WHERE client_id = ?"
getClientsAll = "SELECT client_id, secret, name, web_site, email, enabled, paid FROM client "
searchClientByName = "SELECT c.client_id, c.secret, c.name, c.web_site, c.email, c.enabled, c.paid " +
"FROM client c where c.name like ? "
deleteClient = "DELETE FROM client WHERE client_id = ? "
//Redirect URI queries
insertRedirectURI = "INSERT INTO client_redirect_uri (uri, client_id) values(?, ?)"
getRedirectURIList = "SELECT id, uri, client_id FROM client_redirect_uri WHERE client_id = ? "
getRedirectURI = "SELECT id, uri, client_id FROM client_redirect_uri WHERE client_id = ? and uri = ? "
deleteAllRedirectURI = "DELETE FROM client_redirect_uri WHERE client_id = ? "
deleteRedirectURI = "DELETE FROM client_redirect_uri WHERE id = ?"
//Allowed URI queries
insertAllowedURI = "INSERT INTO client_allowed_uri (uri, client_id) values(?, ?) "
updateAllowedURI = "UPDATE client_allowed_uri SET uri = ? WHERE id = ? "
getAllowedURIByID = "SELECT id, uri, client_id from client_allowed_uri WHERE id = ? "
getAllowedURIList = "SELECT id, uri, client_id from client_allowed_uri WHERE client_id = ? order by uri "
getAllowedURI = "SELECT id, uri, client_id from client_allowed_uri WHERE client_id = ? and uri = ? "
deleteAllowedURI = "DELETE FROM client_allowed_uri WHERE id = ? "
//Role
insertRole = "INSERT INTO client_role (role, client_id) values(?, ?) "
getRoleList = "SELECT id, role, client_id FROM client_role WHERE client_id = ? "
deleteRole = "DELETE FROM client_role WHERE id = ? "
//Scope
insertScope = "INSERT INTO client_scope (scope, client_id) values(?, ?) "
getScopeList = "SELECT id, scope, client_id FROM client_scope WHERE client_id = ? "
deleteScope = "DELETE FROM client_scope WHERE id = ? "
//RoleURI
insertRoleURI = "INSERT INTO uri_role (client_role_id, client_allowed_uri_id) values(?, ?) "
getRoleURIList = "SELECT client_role_id, client_allowed_uri_id FROM uri_role WHERE client_role_id = ?"
roleURIJoin = "SELECT cr.id as role_id, cr.role, " +
"cau.id as uri_id, cau.uri, cr.client_id " +
"FROM client_role cr inner join " +
"uri_role ur on cr.id = ur.client_role_id " +
"left join client_allowed_uri cau on cau.id = ur.client_allowed_uri_id " +
"WHERE cr.client_id = ? " +
"order by ur.client_role_id "
deleteRoleURI = "DELETE FROM uri_role WHERE client_role_id = ? and client_allowed_uri_id = ? "
//Refresh Token
insertRefreshToken = "INSERT INTO refresh_token (token) values(?)"
updateRefreshToken = "UPDATE refresh_token SET token = ? WHERE id = ? "
getRefreshToken = "SELECT id, token FROM refresh_token WHERE id = ? "
deleteRefreshToken = "DELETE FROM refresh_token WHERE id = ? "
//Access Token
insertAccessToken = "INSERT INTO access_token (token, expires, refresh_token_id) values(?, ?, ?) "
insertAccessTokenNull = "INSERT INTO access_token (token, expires) values(?, ?) "
updateAccessToken = "UPDATE access_token SET token = ?, expires = ?, refresh_token_id = ? WHERE id = ? "
updateAccessTokenNull = "UPDATE access_token SET token = ?, expires = ? WHERE id = ? "
getAccessToken = "SELECT id, token, expires, refresh_token_id FROM access_token WHERE id = ? "
deleteAccessToken = "DELETE FROM access_token WHERE id = ? "
//Auth Code
insertAuthCode = "INSERT INTO authorization_code (client_id, user_id, expires, access_token_id, randon_auth_code, already_used) values(?, ?, ?, ?, ?, ?) "
updateAuthCode = "UPDATE authorization_code SET randon_auth_code = ?, already_used = ? " +
"WHERE authorization_code = ? "
updateAuthCodeToken = "UPDATE authorization_code SET expires = ? " +
"WHERE authorization_code = ? "
getByAuthorizationCodeClientUser = "SELECT authorization_code, client_id, user_id, expires, access_token_id, randon_auth_code, already_used " +
"FROM authorization_code WHERE client_id = ? and user_id = ?"
getAuthorizationCodeByCode = "SELECT authorization_code, client_id, user_id, expires, access_token_id, randon_auth_code, already_used " +
"FROM authorization_code WHERE randon_auth_code = ?"
getAuthorizationCodeByClientUserScope = "SELECT a.authorization_code, a.client_id, s.scope, a.randon_auth_code, a.already_used " +
"FROM authorization_code a inner join auth_code_scope s " +
"on a.authorization_code = s.authorization_code " +
"WHERE a.client_id = ? and a.user_id = ? and s.scope = ?"
deleteAuthCode = "DELETE FROM authorization_code WHERE client_id = ? and user_id = ?"
deleteAuthCodeByCode = "DELETE FROM authorization_code WHERE authorization_code = ?"
//Auth Code Scope
insertAuthCodeScope = "INSERT INTO auth_code_scope (scope, authorization_code) values(?, ?) "
getAuthorizationCodeScopeList = "SELECT id, scope, authorization_code " +
"FROM auth_code_scope WHERE authorization_code = ?"
deleteAllAuthCodeScope = "DELETE FROM auth_code_scope WHERE authorization_code = ?"
//Auth Code Revolk
insertAuthCodeRevolk = "INSERT INTO auth_code_revoke (authorization_code) values(?) "
getAuthCodeRevolk = "SELECT id, authorization_code FROM auth_code_revoke WHERE authorization_code = ?"
deleteAuthCodeRevolk = "DELETE FROM auth_code_revoke WHERE authorization_code = ?"
//Grant Types
insertClientGrantType = "INSERT INTO client_grant_type (grant_type, client_id) values(?, ?) "
getClientGrantTypeList = "SELECT * FROM client_grant_type WHERE client_id = ?"
deleteClientGrantType = "DELETE FROM client_grant_type WHERE id = ?"
//Implicit Grant
insertImplicitGrant = "INSERT INTO implicit_grant (client_id, user_id, access_token_id) values(?, ?, ?) "
getImplicitGrant = "SELECT id, client_id, user_id, access_token_id " +
"FROM implicit_grant WHERE client_id = ? and user_id = ? "
getImplicitGrantByScope = "SELECT i.id, i.client_id, s.scope, i.access_token_id " +
"FROM implicit_grant i inner join implicit_scope s " +
"on i.id = s.implicit_grant_id " +
"WHERE i.client_id = ? and i.user_id = ? and s.scope = ?"
deleteImplicitGrant = "DELETE FROM implicit_grant WHERE client_id = ? and user_id = ? "
deleteImplicitGrantByID = "DELETE FROM implicit_grant WHERE id = ? "
//Implicit Scope
insertImplicitScope = "INSERT INTO implicit_scope (scope, implicit_grant_id) values(?, ?) "
getImplicitScopeList = "SELECT id, scope, implicit_grant_id " +
"FROM implicit_scope WHERE implicit_grant_id = ?"
deleteImplicitScope = "DELETE FROM implicit_scope WHERE implicit_grant_id = ?"
//Password grant
insertPasswordGrant = "INSERT INTO password_grant (client_id, user_id, access_token_id) values(?, ?, ?) "
getPasswordGrant = "SELECT id, client_id, user_id, access_token_id " +
"FROM password_grant WHERE client_id = ? and user_id = ?"
deletePasswordGrantByID = "DELETE FROM password_grant WHERE id = ? "
//Credentials Grant
insertCredentialsGrant = "INSERT INTO credentials_grant (client_id, access_token_id) values(?, ?) "
getCredentialsGrant = "SELECT id, client_id, access_token_id " +
"FROM credentials_grant WHERE client_id = ?"
deleteCredentialsGrant = "DELETE FROM credentials_grant WHERE id = ? "
//keys
getAccessTokenKey = "SELECT * FROM access_token_key "
getRefreshTokenKey = "SELECT * FROM refresh_token_key"
getSessionKey = "SELECT * FROM session_key"
)