1 # SPDX-License-Identifier: EPL-1.0
2 ##############################################################################
3 # Copyright (c) 2019, 2023 The Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Eclipse Public License v1.0
7 # which accompanies this distribution, and is available at
8 # http://www.eclipse.org/legal/epl-v10.html
9 ##############################################################################
10 """Helper script to get access_token for lfid api."""
11 from __future__ import annotations
14 from typing import Tuple
17 from oauth2client import client
19 from lftools import config
22 def oauth_helper() -> Tuple[str, str]:
23 """Helper script to get access_token for lfid api."""
24 logging.getLogger("oauth2client").setLevel(logging.ERROR)
25 client_id: str = str(config.get_setting("lfid", "clientid"))
26 client_secret: str = str(config.get_setting("lfid", "client_secret"))
27 refresh_token: str = str(config.get_setting("lfid", "refresh_token"))
28 token_uri: str = str(config.get_setting("lfid", "token_uri"))
29 url: str = str(config.get_setting("lfid", "url"))
31 credentials: client.Oauth2Credentials = client.OAuth2Credentials(
32 access_token=None, # set access_token to None since we use a refresh token
34 client_secret=client_secret,
35 refresh_token=refresh_token,
40 credentials.refresh(httplib2.Http())
41 access_token: str = credentials.access_token
42 return access_token, url