Ejemplo n.º 1
0
async def main():
    nonce = create_secret()
    aiogoogle = Aiogoogle(client_creds=CLIENT_CREDS)
    uri = aiogoogle.openid_connect.authorization_url(
        client_creds=CLIENT_CREDS,
        nonce=nonce,
        access_type='offline',
        include_granted_scopes=True,
        prompt='select_account')
    webbrowser.open_new_tab(uri)
    grant = input('Paste the code you received here, then press Enter')
    full_user_creds = await aiogoogle.openid_connect.build_user_creds(
        grant=grant, client_creds=CLIENT_CREDS, nonce=nonce, verify=False)
    full_user_info = await aiogoogle.openid_connect.get_user_info(
        full_user_creds)
    print(
        f"full_user_creds: {pprint.pformat(full_user_creds)}\n\nfull_user_info: {pprint.pformat(full_user_info)}"
    )
Ejemplo n.º 2
0
Archivo: add.py Proyecto: Na3aga/gmbot
async def add(message: types.Message, state: FSMContext):
    email = message.text.strip()
    if not match(r'^[\w\.-]+@gmail\.com$', email):
        logging.info(f"Mail {email} was rejected")
        await message.answer('Невідомий формат пошти')
        await state.finish()
        return
    state_account = create_secret()
    chat_id = message.chat.id
    chat_type = message.chat.type
    auth_uri = await gmail_API.authorize_uri(email, state_account)
    text = 'Надайте доступ до читання повідомлень вашої пошти ' + auth_uri
    await message.answer(text)
    current_states.update({
        state_account: {
            'chat_id': chat_id,
            'email': email,
            'chat_type': chat_type
        }
    })
    await state.finish()
Ejemplo n.º 3
0
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"]
CLIENT_CREDS = {
    "client_id": config["client_creds"]["client_id"],
    "client_secret": config["client_creds"]["client_secret"],
    "scopes": config["client_creds"]["scopes"],
    "redirect_uri": "http://*****:*****@app.route("/authorize")
def authorize(request):
    if aiogoogle.openid_connect.is_ready(CLIENT_CREDS):
        uri = aiogoogle.openid_connect.authorization_url(
            client_creds=CLIENT_CREDS,
            state=state,
Ejemplo n.º 4
0
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"]
CLIENT_CREDS = {
    "client_id": config["client_creds"]["client_id"],
    "client_secret": config["client_creds"]["client_secret"],
    "scopes": config["client_creds"]["scopes"],
    "redirect_uri": "http://localhost:5000/callback/aiogoogle",
}
state = (
    create_secret()
)  # Shouldn't be a global or a hardcoded variable. should be tied to a session or a user and shouldn't be used more than once
nonce = (
    create_secret()
)  # Shouldn't be a global or a hardcoded variable. should be tied to a session or a user and shouldn't be used more than once

LOCAL_ADDRESS = "localhost"
LOCAL_PORT = "5000"

app = Sanic(__name__)
aiogoogle = Aiogoogle(client_creds=CLIENT_CREDS)

# ----------------------------------------#
#                                        #
# **Step A (Check OAuth2 figure above)** #
#                                        #
Ejemplo n.º 5
0
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"]
CLIENT_CREDS = {
    "client_id": config["client_creds"]["client_id"],
    "client_secret": config["client_creds"]["client_secret"],
    "scopes": config["client_creds"]["scopes"],
    "redirect_uri": "http://localhost:5000/callback/aiogoogle",
}
state = create_secret()

LOCAL_ADDRESS = "localhost"
LOCAL_PORT = "5000"

app = Sanic(__name__)
aiogoogle = Aiogoogle(client_creds=CLIENT_CREDS)


async def refresh(full_user_creds):
    return await aiogoogle.oauth2.refresh(full_user_creds, CLIENT_CREDS)


def expire_creds_then_refresh(full_user_creds):
    import datetime
Ejemplo n.º 6
0
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']
CLIENT_CREDS = {
    'client_id': config['client_creds']['client_id'],
    'client_secret': config['client_creds']['client_secret'],
    'scopes': config['client_creds']['scopes'],
    'redirect_uri': 'http://localhost:5000/callback/aiogoogle',
}
state = create_secret(
)  # Shouldn't be a global or a hardcoded variable. should be tied to a session or a user and shouldn't be used more than once
nonce = create_secret(
)  # Shouldn't be a global or a hardcoded variable. should be tied to a session or a user and shouldn't be used more than once

LOCAL_ADDRESS = 'localhost'
LOCAL_PORT = '5000'

app = Sanic(__name__)
aiogoogle = Aiogoogle(client_creds=CLIENT_CREDS)

#----------------------------------------#
#                                        #
# **Step A (Check OAuth2 figure above)** #
#                                        #
#----------------------------------------#