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.
-
#introspect(token:, token_type_hint: nil, client_id: nil, client_secret: nil) ⇒ Oauth2Introspection
Introspect an OAuth2 access token or refresh token.
-
#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.
5 6 7 |
# File 'lib/appwrite/services/oauth2.rb', line 5 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.
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 |
# File 'lib/appwrite/services/oauth2.rb', line 20 def approve( grant_id:, authorization_details: nil, scope: nil ) if grant_id.nil? raise Appwrite::Exception.new('Missing required parameter: "grantId"') end api_path = '/oauth2/{project_id}/approve' .gsub('{project_id}', @client.encode_path(@client.get_config('project'))) 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.
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 |
# File 'lib/appwrite/services/oauth2.rb', line 74 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.encode_path(@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.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/appwrite/services/oauth2.rb', line 145 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.encode_path(@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.
205 206 207 208 209 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 205 def ( client_id: nil, scope: nil, authorization_details: nil, resource: nil, audience: nil ) api_path = '/oauth2/{project_id}/device_authorization' .gsub('{project_id}', @client.encode_path(@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.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/appwrite/services/oauth2.rb', line 245 def create_grant( user_code: ) if user_code.nil? raise Appwrite::Exception.new('Missing required parameter: "userCode"') end api_path = '/oauth2/{project_id}/grants' .gsub('{project_id}', @client.encode_path(@client.get_config('project'))) 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.
405 406 407 408 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 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/appwrite/services/oauth2.rb', line 405 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 ) 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_path = '/oauth2/{project_id}/par' .gsub('{project_id}', @client.encode_path(@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, } 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.
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/appwrite/services/oauth2.rb', line 593 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 ) if grant_type.nil? raise Appwrite::Exception.new('Missing required parameter: "grantType"') end api_path = '/oauth2/{project_id}/token' .gsub('{project_id}', @client.encode_path(@client.get_config('project'))) 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.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/appwrite/services/oauth2.rb', line 280 def get_grant( grant_id: ) if grant_id.nil? || grant_id == '' raise Appwrite::Exception.new('Missing required parameter: "grantId"') end api_path = '/oauth2/{project_id}/grants/{grant_id}' .gsub('{project_id}', @client.encode_path(@client.get_config('project'))) .gsub('{grant_id}', @client.encode_path(grant_id)) 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 |
#introspect(token:, token_type_hint: nil, client_id: nil, client_secret: nil) ⇒ Oauth2Introspection
Introspect an OAuth2 access token or refresh token. Authenticate with an
API key holding the oauth2.introspect scope to introspect any token in
the project, or with the client credentials of the app the token was issued
to.
317 318 319 320 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 |
# File 'lib/appwrite/services/oauth2.rb', line 317 def introspect( token:, token_type_hint: nil, client_id: nil, client_secret: nil ) if token.nil? raise Appwrite::Exception.new('Missing required parameter: "token"') end api_path = '/oauth2/{project_id}/introspect' .gsub('{project_id}', @client.encode_path(@client.get_config('project'))) 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, response_type: Models::Oauth2Introspection ) 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.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/appwrite/services/oauth2.rb', line 360 def list_organizations( limit: nil, offset: nil, search: nil ) api_path = '/oauth2/{project_id}/organizations' .gsub('{project_id}', @client.encode_path(@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.
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/appwrite/services/oauth2.rb', line 474 def list_projects( limit: nil, offset: nil, search: nil ) api_path = '/oauth2/{project_id}/projects' .gsub('{project_id}', @client.encode_path(@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.
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/appwrite/services/oauth2.rb', line 509 def reject( grant_id: ) if grant_id.nil? raise Appwrite::Exception.new('Missing required parameter: "grantId"') end api_path = '/oauth2/{project_id}/reject' .gsub('{project_id}', @client.encode_path(@client.get_config('project'))) 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.
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/appwrite/services/oauth2.rb', line 545 def revoke( token:, token_type_hint: nil, client_id: nil, client_secret: nil ) if token.nil? raise Appwrite::Exception.new('Missing required parameter: "token"') end api_path = '/oauth2/{project_id}/revoke' .gsub('{project_id}', @client.encode_path(@client.get_config('project'))) 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 |