od_pref.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:onedrived-dev 作者: xybu 项目源码 文件源码
def authenticate_account(get_auth_url=False, code=None, for_business=False):
    if for_business:
        error(translator['od_pref.authenticate_account.for_business_unsupported'])
        return
    authenticator = od_auth.OneDriveAuthenticator()
    click.echo(translator['od_pref.authenticate_account.permission_note'])
    if code is None:
        click.echo(translator['od_pref.authenticate_account.paste_url_note'])
        click.echo('\n' + click.style(authenticator.get_auth_url(), underline=True) + '\n')
        if get_auth_url:
            return
        click.echo(translator['od_pref.authenticate_account.paste_url_instruction'].format(
            redirect_url=click.style(authenticator.APP_REDIRECT_URL, bold=True)))
        url = click.prompt(translator['od_pref.authenticate_account.paste_url_prompt'], type=str)
        code = extract_qs_param(url, 'code')
        if code is None:
            error(translator['od_pref.authenticate_account.error.code_not_found_in_url'])
            return

    try:
        authenticator.authenticate(code)
        success(translator['od_pref.authenticate_account.success.authorized'])
        save_account(authenticator)
    except Exception as e:
        error(translator['od_pref.authenticate_account.error.authorization'].format(error_message=str(e)))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号