How to use the authlib.common.security.generate_token function in Authlib

To help you get started, we’ve selected a few Authlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lepture / authlib / tests / py3 / test_httpx_client / test_async_oauth2_client.py View on Github external
def test_code_challenge():
    sess = AsyncOAuth2Client('foo', code_challenge_method='S256')

    url = 'https://example.com/authorize'
    auth_url, _ = sess.create_authorization_url(
        url, code_verifier=generate_token(48))
    assert 'code_challenge=' in auth_url
    assert 'code_challenge_method=S256' in auth_url
github lepture / authlib / authlib / oauth2 / rfc7591 / endpoint.py View on Github external
def generate_client_id(self):
        """Generate ``client_id`` value. Developers MAY rewrite this method
        to use their own way to generate ``client_id``.
        """
        return generate_token(42)
github lepture / authlib / authlib / oauth2 / rfc8628 / endpoint.py View on Github external
def create_digital_user_code():
    base = '0123456789'
    return '-'.join([
        generate_token(3, base),
        generate_token(3, base),
        generate_token(3, base),
    ])
github lepture / authlib / authlib / oauth2 / rfc8628 / endpoint.py View on Github external
def generate_device_code(self):
        """A method to generate ``device_code`` value for device authorization
        endpoint. This method will generate a random string of 42 characters.
        Developers can rewrite this method to create their own ``device_code``.
        """
        return generate_token(42)
github lepture / authlib / authlib / integrations / flask_oauth2 / authorization_server.py View on Github external
def token_generator(*args, **kwargs):
            return generate_token(length)
        return token_generator
github indico / newdle / newdle / auth.py View on Github external
def login():
    if current_app.config['SKIP_LOGIN']:
        payload = {'error': None, 'token': app_token_from_dummy()}
        return render_template('login_result.html', payload=payload)

    session['oidc.nonce'] = nonce = generate_token(20)
    return oauth.oidc.authorize_redirect(
        url_for('.login_oauth_oidc', _external=True), nonce=nonce
    )
github lepture / authlib / authlib / flask / oauth2 / cache.py View on Github external
def create_authorization_code(self, client, grant_user, request):
            code = generate_token(48)
            data = dict(
                code=code,
                client_id=client.client_id,
                redirect_uri=request.redirect_uri,
                scope=request.scope,
                user_id=grant_user.get_user_id(),
            )
            key = key_tpl.format(code, client.client_id)
            cache.set(key, data, timeout=600)
            return code
github lepture / authlib / authlib / oauth2 / rfc8628 / endpoint.py View on Github external
def create_string_user_code():
    base = 'BCDFGHJKLMNPQRSTVWXZ'
    return '-'.join([generate_token(4, base), generate_token(4, base)])