Class: Appwrite::Oauth2

Inherits:
Service show all
Defined in:
lib/appwrite/services/oauth2.rb

Instance Method Summary collapse

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.

Parameters:

  • grant_id (String) —

    Grant ID made during authorization, provided to consent screen in URL search params.

  • authorization_details (String) (defaults to: nil) —

    Enriched authorization_details the user consented to, replacing what the client requested. Each entry must use a type the project accepts. Optional; omit to keep the originally requested details.

  • scope (String) (defaults to: nil) —

    Space-separated scopes the user consented to. Must be a subset of the scopes originally requested; identity scopes such as openid are always retained. Optional; omit to keep the originally requested scopes.

Returns:

  • (Oauth2Approve)


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: 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.

Parameters:

  • client_id (String) (defaults to: nil) —

    OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL.

  • redirect_uri (String) (defaults to: nil) —

    Redirect URI where visitor will be redirected after authorization, whether successful or not.

  • response_type (String) (defaults to: nil) —

    OAuth2 / OIDC response type. One of code (Authorization Code Flow), id_token (Implicit Flow, OIDC login only), or code id_token (Hybrid Flow).

  • scope (String) (defaults to: nil) —

    Space-separated OAuth2 scopes. Can include project scopes, and built-in scopes: openid, email, profile, phone.

  • state (String) (defaults to: nil) —

    OAuth2 state. You receive this back in the redirect URI.

  • nonce (String) (defaults to: nil) —

    OIDC nonce parameter to prevent replay attacks. Required when response_type includes id_token.

  • code_challenge (String) (defaults to: nil) —

    PKCE code challenge. Required when OAuth2 app is public.

  • code_challenge_method (String) (defaults to: nil) —

    PKCE code challenge method. Required when OAuth2 app is public.

  • prompt (String) (defaults to: nil) —

    OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account.

  • max_age (Integer) (defaults to: nil) —

    OIDC max_age paraleter for customization of consent screen. Maximum allowable elapsed time in seconds since the user last authenticated. If exceeded, re-authentication is required.

  • authorization_details (String) (defaults to: nil) —

    Rich authorization request. JSON array of objects, each with a type and project-defined fields

  • resource (Array) (defaults to: nil) —

    RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment.

  • audience (String) (defaults to: nil) —

    Compatibility alias for a single OAuth2 resource indicator URI.

  • request_uri (String) (defaults to: nil) —

    OAuth2 authorization request handle returned by the pushed authorization request endpoint.

Returns:

  • (Oauth2Authorize)


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 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
)
    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: 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.

Parameters:

  • client_id (String) (defaults to: nil) —

    OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL.

  • redirect_uri (String) (defaults to: nil) —

    Redirect URI where visitor will be redirected after authorization, whether successful or not.

  • response_type (String) (defaults to: nil) —

    OAuth2 / OIDC response type. One of code (Authorization Code Flow), id_token (Implicit Flow, OIDC login only), or code id_token (Hybrid Flow).

  • scope (String) (defaults to: nil) —

    Space-separated OAuth2 scopes. Can include project scopes, and built-in scopes: openid, email, profile, phone.

  • state (String) (defaults to: nil) —

    OAuth2 state. You receive this back in the redirect URI.

  • nonce (String) (defaults to: nil) —

    OIDC nonce parameter to prevent replay attacks. Required when response_type includes id_token.

  • code_challenge (String) (defaults to: nil) —

    PKCE code challenge. Required when OAuth2 app is public.

  • code_challenge_method (String) (defaults to: nil) —

    PKCE code challenge method. Required when OAuth2 app is public.

  • prompt (String) (defaults to: nil) —

    OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account.

  • max_age (Integer) (defaults to: nil) —

    OIDC max_age paraleter for customization of consent screen. Maximum allowable elapsed time in seconds since the user last authenticated. If exceeded, re-authentication is required.

  • authorization_details (String) (defaults to: nil) —

    Rich authorization request. JSON array of objects, each with a type and project-defined fields

  • resource (Array) (defaults to: nil) —

    RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment.

  • audience (String) (defaults to: nil) —

    Compatibility alias for a single OAuth2 resource indicator URI.

  • request_uri (String) (defaults to: nil) —

    OAuth2 authorization request handle returned by the pushed authorization request endpoint.

Returns:

  • (Oauth2Authorize)


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 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
)
    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: 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.

Parameters:

  • client_id (String) (defaults to: nil) —

    OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL.

  • scope (String) (defaults to: nil) —

    Space-separated OAuth2 scopes. Can include project scopes, and built-in scopes: openid, email, profile.

  • authorization_details (String) (defaults to: nil) —

    Rich authorization request. JSON array of objects, each with a type and project-defined fields

  • resource (Array) (defaults to: nil) —

    RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment.

  • audience (String) (defaults to: nil) —

    Compatibility alias for a single OAuth2 resource indicator URI.

Returns:

  • (Oauth2DeviceAuthorization)


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 create_device_authorization(
    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: 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.

Parameters:

  • user_code (String) —

    User code displayed on the device.

Returns:

  • (Oauth2Grant)


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.

Parameters:

  • client_id (String) —

    OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL.

  • redirect_uri (String) —

    Redirect URI where visitor will be redirected after authorization, whether successful or not.

  • response_type (String) —

    OAuth2 / OIDC response type.

  • scope (String) (defaults to: nil) —

    Space-separated OAuth2 scopes. Can include project scopes, and built-in scopes: openid, email, profile, phone.

  • state (String) (defaults to: nil) —

    OAuth2 state. You receive this back in the redirect URI.

  • nonce (String) (defaults to: nil) —

    OIDC nonce parameter to prevent replay attacks. Required when response_type includes id_token.

  • code_challenge (String) (defaults to: nil) —

    PKCE code challenge. Required when OAuth2 app is public.

  • code_challenge_method (String) (defaults to: nil) —

    PKCE code challenge method. Required when OAuth2 app is public.

  • prompt (String) (defaults to: nil) —

    OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account.

  • max_age (Integer) (defaults to: nil) —

    OIDC max_age parameter for customization of consent screen.

  • authorization_details (String) (defaults to: nil) —

    Rich authorization request. JSON array of objects, each with a type and project-defined fields

  • resource (Array) (defaults to: nil) —

    RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment.

  • audience (String) (defaults to: nil) —

    Compatibility alias for a single OAuth2 resource indicator URI.

Returns:

  • (Oauth2PAR)


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: 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.

Parameters:

  • grant_type (String) —

    OAuth2 grant type. Can be one of: authorization_code, refresh_token, urn:ietf:params:oauth:grant-type:device_code.

  • code (String) (defaults to: nil) —

    Authorization code to be exchanged for access and refresh tokens. Required for authorization_code grant type.

  • refresh_token (String) (defaults to: nil) —

    Refresh token to be exchanged for a new access and refresh tokens. Required for refresh_token grant type.

  • device_code (String) (defaults to: nil) —

    Device code obtained from the device authorization endpoint. Required for urn:ietf:params:oauth:grant-type:device_code grant type.

  • client_id (String) (defaults to: nil) —

    OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL.

  • client_secret (String) (defaults to: nil) —

    OAuth2 client secret. Required for confidential apps.

  • code_verifier (String) (defaults to: nil) —

    PKCE code verifier. Required for public apps.

  • redirect_uri (String) (defaults to: nil) —

    Redirect URI. Required for authorization_code grant type.

  • resource (Array) (defaults to: nil) —

    RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment.

  • audience (String) (defaults to: nil) —

    Compatibility alias for a single OAuth2 resource indicator URI.

Returns:

  • (Oauth2Token)


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.

Parameters:

  • grant_id (String) —

    Grant ID made during authorization, provided to consent screen in URL search params.

Returns:

  • (Oauth2Grant)


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.

Parameters:

  • token (String) —

    The access token or refresh token to introspect.

  • token_type_hint (String) (defaults to: nil) —

    Type of token to introspect. Can be one of: access_token or refresh_token.

  • client_id (String) (defaults to: nil) —

    OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL.

  • client_secret (String) (defaults to: nil) —

    OAuth2 client secret.

Returns:

  • (Oauth2Introspection)


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.

Parameters:

  • limit (Integer) (defaults to: nil) —

    Maximum number of organizations to return. Between 1 and 5000.

  • offset (Integer) (defaults to: nil) —

    Number of organizations to skip before returning results. Used for pagination.

  • search (String) (defaults to: nil) —

    Search term to filter your list results. Max length: 256 chars.

Returns:

  • (Oauth2OrganizationList)


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.

Parameters:

  • limit (Integer) (defaults to: nil) —

    Maximum number of projects to return. Between 1 and 5000.

  • offset (Integer) (defaults to: nil) —

    Number of projects to skip before returning results. Used for pagination.

  • search (String) (defaults to: nil) —

    Search term to filter your list results. Max length: 256 chars.

Returns:

  • (Oauth2ProjectList)


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.

Parameters:

  • grant_id (String) —

    Grant ID made during authorization, provided to consent screen in URL search params.

Returns:

  • (Oauth2Reject)


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.

Parameters:

  • token (String) —

    The access or refresh token to revoke.

  • token_type_hint (String) (defaults to: nil) —

    Type of token to revoke (access_token or refresh_token).

  • client_id (String) (defaults to: nil) —

    OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL.

  • client_secret (String) (defaults to: nil) —

    OAuth2 client secret. Required for confidential apps; omitted for public apps.

Returns:

  • []



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