示例#1
0
def convert_user_creds(user_creds):
    creds = UserCreds(
        access_token=user_creds.token,
        refresh_token=user_creds.refresh_token,
        expires_at=user_creds.expiry or None,
    )
    return creds
示例#2
0
def _get_user_creds(creds):
    return UserCreds(
        access_token=creds.token,
        refresh_token=creds.refresh_token,
        expires_at=creds.expiry.isoformat(),
        scopes=creds.scopes,
    )
示例#3
0
def get_user_creds(credentials_file, token_file, host, port):
    creds = None
    if os.path.exists(token_file):
        with open(token_file, "rb") as f:
            creds = pickle.load(f)

    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                credentials_file, SCOPES)
            creds = flow.run_local_server(host=host, port=port)

        with open(token_file, "wb") as f:
            pickle.dump(creds, f)

    # Here are all the common attributes between google.oauth2.credentials.Credentials
    # and aiogoogle.auth.creds.UserCreds. UserCreds has more attributes, but
    # I'm guessing they're not required.
    return UserCreds(
        access_token=creds.token,
        refresh_token=creds.refresh_token,
        expires_at=creds.expiry.isoformat(),
        scopes=creds.scopes,
        id_token=creds.id_token,
        token_uri=creds.token_uri,
    )
示例#4
0
sys.path.append("..")

# This is being used in other examples. Don't remove
from aiogoogle import Aiogoogle  # noqa: F401, E402  imported but unused & module level import not at top of file
from aiogoogle.auth.creds import (  # noqa: E402 module level import not at top of file
    UserCreds, ClientCreds, ApiKey,
)  # noqa: F401  imported but unused

try:
    with open("keys.yaml", "r") as stream:
        config = yaml.load(stream, Loader=yaml.FullLoader)
except Exception as e:
    print("Rename _keys.yaml to keys.yaml")
    raise e

email = config["user_creds"]["email"]

user_creds = UserCreds(
    access_token=config["user_creds"]["access_token"],
    refresh_token=config["user_creds"]["refresh_token"],
    expires_at=config["user_creds"]["expires_at"] or None,
)

api_key = ApiKey(config["api_key"])

client_creds = ClientCreds(
    client_id=config["client_creds"]["client_id"],
    client_secret=config["client_creds"]["client_secret"],
    scopes=config["client_creds"]["scopes"],
)
示例#5
0
#!/usr/bin/python3.7

import sys, yaml
sys.path.append('..')

from aiogoogle import Aiogoogle
from aiogoogle.auth.creds import UserCreds, ClientCreds, ApiKey

try:
    with open("keys.yaml", 'r') as stream:
        config = yaml.load(stream)
except Exception as e:
    print('Rename _keys.yaml to keys.yaml')
    raise e

email = config['user_creds']['email']

user_creds = UserCreds(
    access_token=config['user_creds']['access_token'],
    refresh_token=config['user_creds']['refresh_token'],
    expires_at=config['user_creds']['expires_at'],
)

api_key = ApiKey(config['api_key'])

client_creds = ClientCreds(
    client_id=config['client_creds']['client_id'],
    client_secret=config['client_creds']['client_secret'],
    scopes=config['client_creds']['scopes'],
)