Class: Appwrite::Oauth2
- Defined in:
- lib/appwrite/services/oauth2.rb
Instance Method Summary collapse
-
#approve(grant_id:, authorization_details: nil, scope: nil) ⇒ Oauth2Approve
Approve an OAuth2 grant after the user gives consent.
-
#authorize(client_id: nil, redirect_uri: nil, response_type: nil, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil, request_uri: nil) ⇒ Oauth2Authorize
Begin the OAuth2 authorization flow.
-
#authorize_post(client_id: nil, redirect_uri: nil, response_type: nil, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil, request_uri: nil) ⇒ Oauth2Authorize
Begin the OAuth2 authorization flow.
-
#create_device_authorization(client_id: nil, scope: nil, authorization_details: nil, resource: nil, audience: nil) ⇒ Oauth2DeviceAuthorization
Start the OAuth2 Device Authorization Grant.
-
#create_grant(user_code:) ⇒ Oauth2Grant
Exchange a device flow user code for an OAuth2 grant.
-
#create_par(client_id:, redirect_uri:, response_type:, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil) ⇒ Oauth2PAR
Store an OAuth2 authorization request server-side and receive a short-lived request_uri handle for the authorize endpoint.
-
#create_token(grant_type:, code: nil, refresh_token: nil, device_code: nil, client_id: nil, client_secret: nil, code_verifier: nil, redirect_uri: nil, resource: nil, audience: nil) ⇒ Oauth2Token
Exchange an OAuth2 authorization code, refresh token, or device code for access and refresh tokens.
-
#get_grant(grant_id:) ⇒ Oauth2Grant
Get an OAuth2 grant by its ID.
-
#initialize(client) ⇒ Oauth2
constructor
A new instance of Oauth2.
-
#list_organizations(limit: nil, offset: nil, search: nil) ⇒ Oauth2OrganizationList
List the organizations the OAuth2 access token can access.
-
#list_projects(limit: nil, offset: nil, search: nil) ⇒ Oauth2ProjectList
List the projects the OAuth2 access token can access.
-
#reject(grant_id:) ⇒ Oauth2Reject
Reject an OAuth2 grant when the user denies consent.
-
#revoke(token:, token_type_hint: nil, client_id: nil, client_secret: nil) ⇒ Object
Revoke an OAuth2 access token or refresh token.
Constructor Details
#initialize(client) ⇒ Oauth2
Returns a new instance of Oauth2.
6 7 8 |
# File 'lib/appwrite/services/oauth2.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#approve(grant_id:, authorization_details: nil, scope: nil) ⇒ Oauth2Approve
Approve an OAuth2 grant after the user gives consent. Returns the
redirectUrl the end user should be sent to. The consent screen may
optionally pass enriched authorization_details to record the concrete
resources the user selected. You can pass Accept header of
application/json to receive a JSON response instead of a redirect.
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 |
# File 'lib/appwrite/services/oauth2.rb', line 21 def approve(grant_id:, authorization_details: nil, scope: nil) api_path = '/oauth2/{project_id}/approve' .gsub('{project_id}', @client.get_config('project')) if grant_id.nil? raise Appwrite::Exception.new('Missing required parameter: "grantId"') end api_params = { grant_id: grant_id, authorization_details: , scope: scope, } api_headers = { "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2Approve ) end |
#authorize(client_id: nil, redirect_uri: nil, response_type: nil, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil, request_uri: nil) ⇒ Oauth2Authorize
Begin the OAuth2 authorization flow. When called without a session, the
user is redirected to the consent screen without grant ID. When called with
a session, the redirect URL includes param for grant ID. You can pass
Accept header of application/json to receive a JSON response instead of a
redirect.
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 |
# File 'lib/appwrite/services/oauth2.rb', line 72 def (client_id: nil, redirect_uri: nil, response_type: nil, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil, request_uri: nil) api_path = '/oauth2/{project_id}/authorize' .gsub('{project_id}', @client.get_config('project')) api_params = { client_id: client_id, redirect_uri: redirect_uri, response_type: response_type, scope: scope, state: state, nonce: nonce, code_challenge: code_challenge, code_challenge_method: code_challenge_method, prompt: prompt, max_age: max_age, authorization_details: , resource: resource, audience: audience, request_uri: request_uri, } api_headers = { "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2Authorize ) end |
#authorize_post(client_id: nil, redirect_uri: nil, response_type: nil, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil, request_uri: nil) ⇒ Oauth2Authorize
Begin the OAuth2 authorization flow. When called without a session, the
user is redirected to the consent screen without grant ID. When called with
a session, the redirect URL includes param for grant ID. You can pass
Accept header of application/json to receive a JSON response instead of a
redirect.
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 155 156 157 158 159 160 161 162 163 |
# File 'lib/appwrite/services/oauth2.rb', line 129 def (client_id: nil, redirect_uri: nil, response_type: nil, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil, request_uri: nil) api_path = '/oauth2/{project_id}/authorize' .gsub('{project_id}', @client.get_config('project')) api_params = { client_id: client_id, redirect_uri: redirect_uri, response_type: response_type, scope: scope, state: state, nonce: nonce, code_challenge: code_challenge, code_challenge_method: code_challenge_method, prompt: prompt, max_age: max_age, authorization_details: , resource: resource, audience: audience, request_uri: request_uri, } api_headers = { "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2Authorize ) end |
#create_device_authorization(client_id: nil, scope: nil, authorization_details: nil, resource: nil, audience: nil) ⇒ Oauth2DeviceAuthorization
Start the OAuth2 Device Authorization Grant. Returns the device code, user code, verification URL, expiration, and polling interval.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/appwrite/services/oauth2.rb', line 175 def (client_id: nil, scope: nil, authorization_details: nil, resource: nil, audience: nil) api_path = '/oauth2/{project_id}/device_authorization' .gsub('{project_id}', @client.get_config('project')) api_params = { client_id: client_id, scope: scope, authorization_details: , resource: resource, audience: audience, } api_headers = { "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2DeviceAuthorization ) end |
#create_grant(user_code:) ⇒ Oauth2Grant
Exchange a device flow user code for an OAuth2 grant. The authenticated user is bound to the pending grant. Pass the returned grant ID to the get grant endpoint to render the consent screen, then to the approve or reject endpoint to complete the flow.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/appwrite/services/oauth2.rb', line 210 def create_grant(user_code:) api_path = '/oauth2/{project_id}/grants' .gsub('{project_id}', @client.get_config('project')) if user_code.nil? raise Appwrite::Exception.new('Missing required parameter: "userCode"') end api_params = { user_code: user_code, } api_headers = { "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2Grant ) end |
#create_par(client_id:, redirect_uri:, response_type:, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil) ⇒ Oauth2PAR
Store an OAuth2 authorization request server-side and receive a short-lived request_uri handle for the authorize endpoint.
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/appwrite/services/oauth2.rb', line 321 def create_par(client_id:, redirect_uri:, response_type:, scope: nil, state: nil, nonce: nil, code_challenge: nil, code_challenge_method: nil, prompt: nil, max_age: nil, authorization_details: nil, resource: nil, audience: nil) api_path = '/oauth2/{project_id}/par' .gsub('{project_id}', @client.get_config('project')) if client_id.nil? raise Appwrite::Exception.new('Missing required parameter: "clientId"') end if redirect_uri.nil? raise Appwrite::Exception.new('Missing required parameter: "redirectUri"') end if response_type.nil? raise Appwrite::Exception.new('Missing required parameter: "responseType"') end api_params = { client_id: client_id, redirect_uri: redirect_uri, response_type: response_type, scope: scope, state: state, nonce: nonce, code_challenge: code_challenge, code_challenge_method: code_challenge_method, prompt: prompt, max_age: max_age, authorization_details: , resource: resource, audience: audience, } api_headers = { "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2PAR ) end |
#create_token(grant_type:, code: nil, refresh_token: nil, device_code: nil, client_id: nil, client_secret: nil, code_verifier: nil, redirect_uri: nil, resource: nil, audience: nil) ⇒ Oauth2Token
Exchange an OAuth2 authorization code, refresh token, or device code for access and refresh tokens.
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/appwrite/services/oauth2.rb', line 488 def create_token(grant_type:, code: nil, refresh_token: nil, device_code: nil, client_id: nil, client_secret: nil, code_verifier: nil, redirect_uri: nil, resource: nil, audience: nil) api_path = '/oauth2/{project_id}/token' .gsub('{project_id}', @client.get_config('project')) if grant_type.nil? raise Appwrite::Exception.new('Missing required parameter: "grantType"') end api_params = { grant_type: grant_type, code: code, refresh_token: refresh_token, device_code: device_code, client_id: client_id, client_secret: client_secret, code_verifier: code_verifier, redirect_uri: redirect_uri, resource: resource, audience: audience, } api_headers = { "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2Token ) end |
#get_grant(grant_id:) ⇒ Oauth2Grant
Get an OAuth2 grant by its ID. Used by the consent screen to display the details of the authorization the user is being asked to approve. A grant can only be read by the user it belongs to, or by server SDK.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/appwrite/services/oauth2.rb', line 244 def get_grant(grant_id:) api_path = '/oauth2/{project_id}/grants/{grant_id}' .gsub('{project_id}', @client.get_config('project')) .gsub('{grant_id}', grant_id) if grant_id.nil? raise Appwrite::Exception.new('Missing required parameter: "grantId"') end api_params = { } api_headers = { "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2Grant ) end |
#list_organizations(limit: nil, offset: nil, search: nil) ⇒ Oauth2OrganizationList
List the organizations the OAuth2 access token can access. Resolves the
token's organization authorization details, expanding the * wildcard
into the concrete set of organizations the user can see.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/appwrite/services/oauth2.rb', line 279 def list_organizations(limit: nil, offset: nil, search: nil) api_path = '/oauth2/{project_id}/organizations' .gsub('{project_id}', @client.get_config('project')) api_params = { limit: limit, offset: offset, search: search, } api_headers = { "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2OrganizationList ) end |
#list_projects(limit: nil, offset: nil, search: nil) ⇒ Oauth2ProjectList
List the projects the OAuth2 access token can access. Resolves the token's
project authorization details, expanding the * wildcard into the
concrete set of projects the user can see.
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/appwrite/services/oauth2.rb', line 377 def list_projects(limit: nil, offset: nil, search: nil) api_path = '/oauth2/{project_id}/projects' .gsub('{project_id}', @client.get_config('project')) api_params = { limit: limit, offset: offset, search: search, } api_headers = { "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2ProjectList ) end |
#reject(grant_id:) ⇒ Oauth2Reject
Reject an OAuth2 grant when the user denies consent. Returns the
redirectUrl the end user should be sent to with an access_denied error.
You can pass Accept header of application/json to receive a JSON response
instead of a redirect.
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/appwrite/services/oauth2.rb', line 409 def reject(grant_id:) api_path = '/oauth2/{project_id}/reject' .gsub('{project_id}', @client.get_config('project')) if grant_id.nil? raise Appwrite::Exception.new('Missing required parameter: "grantId"') end api_params = { grant_id: grant_id, } api_headers = { "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::Oauth2Reject ) end |
#revoke(token:, token_type_hint: nil, client_id: nil, client_secret: nil) ⇒ Object
Revoke an OAuth2 access token or refresh token.
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/appwrite/services/oauth2.rb', line 444 def revoke(token:, token_type_hint: nil, client_id: nil, client_secret: nil) api_path = '/oauth2/{project_id}/revoke' .gsub('{project_id}', @client.get_config('project')) if token.nil? raise Appwrite::Exception.new('Missing required parameter: "token"') end api_params = { token: token, token_type_hint: token_type_hint, client_id: client_id, client_secret: client_secret, } api_headers = { "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, ) end |