MCPcopy
hub / github.com/authlib/authlib / generate

Method generate

authlib/oauth2/rfc7523/token.py:69–96  ·  view source on GitHub ↗

Generate a bearer token for OAuth 2.0 authorization token endpoint. :param client: the client that making the request. :param grant_type: current requested grant_type. :param user: current authorized user. :param expires_in: if provided, use this value as expires_in.

(self, grant_type, client, user=None, scope=None, expires_in=None)

Source from the content-addressed store, hash-verified

67 return data
68
69 def generate(self, grant_type, client, user=None, scope=None, expires_in=None):
70 """Generate a bearer token for OAuth 2.0 authorization token endpoint.
71
72 :param client: the client that making the request.
73 :param grant_type: current requested grant_type.
74 :param user: current authorized user.
75 :param expires_in: if provided, use this value as expires_in.
76 :param scope: current requested scope.
77 :return: Token dict
78 """
79 if expires_in is None:
80 expires_in = self.DEFAULT_EXPIRES_IN
81
82 token_data = self.get_token_data(grant_type, client, expires_in, user, scope)
83 access_token = jwt.encode(
84 {"alg": self.alg},
85 claims=token_data,
86 key=self.secret_key,
87 algorithms=[self.alg],
88 )
89 token = {
90 "token_type": "Bearer",
91 "access_token": access_token,
92 "expires_in": expires_in,
93 }
94 if scope:
95 token["scope"] = scope
96 return token
97
98 def __call__(
99 self,

Callers 1

__call__Method · 0.95

Calls 2

get_token_dataMethod · 0.95
encodeMethod · 0.80

Tested by

no test coverage detected