MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / fetch_token

Method fetch_token

dwave/cloud/auth/flows.py:206–237  ·  view source on GitHub ↗

Exchange ``code`` for access token. Args: code: OAuth 2.0 authorization code to be exchanged for access token. state: Authorization state; should match the one generated when creating the authorize URL.

(self, *, code: str, **kwargs)

Source from the content-addressed store, hash-verified

204 return url
205
206 def fetch_token(self, *, code: str, **kwargs) -> dict:
207 """Exchange ``code`` for access token.
208
209 Args:
210 code:
211 OAuth 2.0 authorization code to be exchanged for access token.
212 state:
213 Authorization state; should match the one generated when creating
214 the authorize URL.
215
216 Note: except for the out-of-band flow, be sure to pass in the
217 ``state`` parameter received on the ``redirect_uri`` for added
218 security.
219 """
220 # make sure states match before proceeding, we shouldn't be tricked
221 # into exchanging arbitrary auth codes.
222 state = kwargs.get('state', None)
223 if state is not None:
224 if state != self.state:
225 raise ValueError('State mismatch')
226
227 token = self.session.fetch_token(
228 url=self.token_endpoint,
229 grant_type='authorization_code',
230 code=code,
231 code_verifier=self.code_verifier,
232 **kwargs)
233
234 logger.debug(f"{type(self).__name__}.fetch_token() = {token!r}")
235 self._save_token_to_creds(token)
236
237 return token
238
239 def refresh_token(self):
240 token = self.session.refresh_token(url=self.token_endpoint)

Callers 4

test_fetch_tokenMethod · 0.95
run_oob_flowMethod · 0.80
exchange_codeMethod · 0.80

Calls 2

_save_token_to_credsMethod · 0.95
getMethod · 0.45

Tested by 2

test_fetch_tokenMethod · 0.76