Oauth2Access

Represents a Discord oauth2 access object, what is returned by Client.activate_authorization_code if activating the authorization code went successfully.

Attributes

access_token : str

Token used for Bearer authorizations, when requesting OAuth2 data about the respective user.

created_at : DateTime

The time when the access was last created or renewed.

expires_after : int

The time in seconds after this access expires.

redirect_url : str

The redirect url with what the user granted the authorization code for the oauth2 scopes for the application.

Can be empty string if application's owner's access was requested.

refresh_token : str

The token used to renew the access token.

Can be empty string if application's owner's access was requested.

scopes : None, tuple of Oauth2Scope

A sequence of the scopes, which the user granted with the access token.

Defaults to None if empty.

Properties

expires_at

Returns when the access expires.

Returns

expires_at : DateTime

Methods

__new__(...)

Creates a new oauth2 access with the given fields.

ParameterTypeOptionalKeyword onlyDescription
access_token

str

Token used for Bearer authorizations, when requesting OAuth2 data about the respective user.

created_at

DateTime

The time when the access was last created or renewed.

expires_after

int

The time in seconds after this access expires.

redirect_url

str

The redirect url with what the user granted the authorization code for the oauth2 scopes for the application.

refresh_token

str

The token used to renew the access token.

scopes

None, iterable of (str, Oauth2Scope)

A sequence of the scopes, which the user granted with the access token.

Raises

TypeError

  • If a parameter's type is incorrect.

ValueError

  • If a parameter's value is incorrect.

copy()

Copies the oauth2 access.

Returns

new : instance<type<self>

copy_with(...)

Copies the oauth2 scopes with the given fields.

ParameterTypeOptionalKeyword onlyDescription
access_token

str

Token used for Bearer authorizations, when requesting OAuth2 data about the respective user.

created_at

DateTime

The time when the access was last created or renewed.

expires_after

int

The time in seconds after this access expires.

redirect_url

str

The redirect url with what the user granted the authorization code for the oauth2 scopes for the application.

refresh_token

str

The token used to renew the access token.

scopes

None, iterable of (str, Oauth2Scope)

A sequence of the scopes, which the user granted with the access token.

Returns

new : instance<type<self>

Raises

TypeError

  • If a parameter's type is incorrect.

ValueError

  • If a parameter's value is incorrect.

from_data(data, redirect_url)

Creates an Oauth2Access.

ParameterTypeDescription
data

dict of (str, object) items

Received access data.

redirect_url

str

The redirect url with what the user granted the authorization code for the oauth2 scopes for the application.

Returns

self : instance<cls>

has_scope(scope)

Returns whether the access has the given scope.

ParameterTypeDescription
scope

Oauth2Scope, str

The scope to check out.

Returns

has_scope : bool

Raises

TypeError

iter_scopes()

Iterates over the oauth2 scopes of the oauth2 access.

This method is an iterable generator.

Yields

scope : Oauth2Scope

to_data(...)

Converts the access to a json serializable object.

ParameterTypeOptionalKeyword onlyDefaultDescription
defaults

bool

False

Whether fields with their default value should be included as well.

Returns

data : dict of (str, object) items

_renew(data)

Renews the access with the given data.

ParameterTypeDescription
data

None or (dict of (str, object))

Requested access data.

__eq__()

Returns whether the two oauth2 access are equal.

__getattr__()

Drops a rich attribute error.

__hash__()

Returns the oauth2 scope's hash value.

__repr__()

Returns the representation of the oath2 access.