예제 #1
0
class OAuth2Token(ModelFactory):
    class Meta:
        model = models.Token
        sqlalchemy_session_persistence = 'flush'

    userid = factory.LazyAttribute(
        lambda _: ('acct:' + FAKER.user_name() + '@example.com'))
    value = factory.LazyAttribute(
        lambda _: (ACCESS_TOKEN_PREFIX + security.token_urlsafe()))
    refresh_token = factory.LazyAttribute(
        lambda _: (REFRESH_TOKEN_PREFIX + security.token_urlsafe()))
    expires = factory.LazyAttribute(lambda _:
                                    (datetime.utcnow() + timedelta(hours=1)))
    authclient = factory.SubFactory(AuthClient)
예제 #2
0
파일: security_test.py 프로젝트: nlisgo/h
def test_token_urlsafe(nbytes):
    tok = token_urlsafe(nbytes)

    # Should be text
    assert isinstance(tok, text_type)
    # Always at least nbytes of data
    assert len(tok) > nbytes
예제 #3
0
def test_token_urlsafe(nbytes):
    tok = token_urlsafe(nbytes)

    # Should be text
    assert isinstance(tok, text_type)
    # Always at least nbytes of data
    assert len(tok) > nbytes
예제 #4
0
파일: token.py 프로젝트: kaydoh/h
class OAuth2Token(ModelFactory):
    class Meta:
        model = models.Token
        sqlalchemy_session_persistence = "flush"

    userid = factory.LazyAttribute(lambda _: (
        "acct:" + FAKER.user_name() + "@example.com"  # pylint:disable=no-member
    ))
    value = factory.LazyAttribute(
        lambda _: (ACCESS_TOKEN_PREFIX + security.token_urlsafe()))
    refresh_token = factory.LazyAttribute(
        lambda _: (REFRESH_TOKEN_PREFIX + security.token_urlsafe()))
    expires = factory.LazyAttribute(lambda _:
                                    (datetime.utcnow() + timedelta(hours=1)))
    refresh_token_expires = factory.LazyAttribute(
        lambda _: (datetime.utcnow() + timedelta(days=7)))
    authclient = factory.SubFactory(AuthClient)
예제 #5
0
class DeveloperToken(ModelFactory):
    class Meta:
        model = models.Token
        sqlalchemy_session_persistence = 'flush'

    userid = factory.LazyAttribute(
        lambda _: ('acct:' + FAKER.user_name() + '@example.com'))
    value = factory.LazyAttribute(
        lambda _: (DEVELOPER_TOKEN_PREFIX + security.token_urlsafe()))
예제 #6
0
파일: token.py 프로젝트: kaydoh/h
class DeveloperToken(ModelFactory):
    class Meta:
        model = models.Token
        sqlalchemy_session_persistence = "flush"

    userid = factory.LazyAttribute(lambda _: (
        "acct:" + FAKER.user_name() + "@example.com"  # pylint:disable=no-member
    ))
    value = factory.LazyAttribute(
        lambda _: (DEVELOPER_TOKEN_PREFIX + security.token_urlsafe()))
예제 #7
0
    def create_token(self, user, authclient):
        """
        Creates a token for the passed-in user without any additional
        verification.

        It is the caller's responsibility to verify the token request, e.g. with
        ``verify_token_request``.

        :param assertion: the user for whom the token should be created.
        :type assertion: h.models.User

        :rtype: h.models.Token
        """
        value = ACCESS_TOKEN_PREFIX + security.token_urlsafe()
        refresh_token = REFRESH_TOKEN_PREFIX + security.token_urlsafe()

        token = models.Token(userid=user.userid,
                             value=value,
                             expires=(utcnow() + TOKEN_TTL),
                             refresh_token=refresh_token,
                             authclient=authclient)
        self.session.add(token)

        return token
예제 #8
0
def add(ctx, name, authority, type_):
    """Create a new OAuth client."""
    request = ctx.obj["bootstrap"]()

    client = models.AuthClient(name=name, authority=authority)
    if type_ == "confidential":
        client.secret = token_urlsafe()
    request.db.add(client)
    request.db.flush()

    id_ = client.id
    secret = client.secret

    request.tm.commit()

    message = f"OAuth client for {authority} created\nClient ID: {id_}"
    if type_ == "confidential":
        message += f"\nClient Secret: {secret}"

    click.echo(message)
예제 #9
0
def add(ctx, name, authority, type_):
    """
    Create a new OAuth client.
    """
    request = ctx.obj['bootstrap']()

    authclient = models.AuthClient(name=name, authority=authority)
    if type_ == 'confidential':
        authclient.secret = token_urlsafe()
    request.db.add(authclient)
    request.db.flush()

    id_ = authclient.id
    secret = authclient.secret

    request.tm.commit()

    message = ('OAuth client for {authority} created\n' 'Client ID: {id}')
    if type_ == 'confidential':
        message += '\nClient Secret: {secret}'

    click.echo(message.format(authority=authority, id=id_, secret=secret))
예제 #10
0
파일: authclient.py 프로젝트: hypothesis/h
def add(ctx, name, authority, type_):
    """
    Create a new OAuth client.
    """
    request = ctx.obj["bootstrap"]()

    authclient = models.AuthClient(name=name, authority=authority)
    if type_ == "confidential":
        authclient.secret = token_urlsafe()
    request.db.add(authclient)
    request.db.flush()

    id_ = authclient.id
    secret = authclient.secret

    request.tm.commit()

    message = "OAuth client for {authority} created\n" "Client ID: {id}"
    if type_ == "confidential":
        message += "\nClient Secret: {secret}"

    click.echo(message.format(authority=authority, id=id_, secret=secret))
예제 #11
0
 def regenerate(self):
     self.value = self.prefix + security.token_urlsafe()
예제 #12
0
파일: service.py 프로젝트: kaydoh/h
 def _generate_refresh_token(_oauth_request):
     return REFRESH_TOKEN_PREFIX + token_urlsafe()
예제 #13
0
파일: service.py 프로젝트: kaydoh/h
 def _generate_access_token(oauth_request):  # pylint: disable=unused-argument
     return ACCESS_TOKEN_PREFIX + token_urlsafe()
예제 #14
0
 def generate_access_token(self, oauth_request):
     return ACCESS_TOKEN_PREFIX + token_urlsafe()
예제 #15
0
파일: token.py 프로젝트: gnott/h
    def __init__(self, **kwargs):
        super(Token, self).__init__(**kwargs)
        self.regenerate()

        if self.expires:
            self.refresh_token = security.token_urlsafe()
예제 #16
0
파일: security_test.py 프로젝트: nlisgo/h
def test_token_urlsafe_no_args():
    tok = token_urlsafe()

    assert isinstance(tok, text_type)
    assert len(tok) > 32
예제 #17
0
파일: token.py 프로젝트: gnott/h
 def regenerate(self):
     self.value = self.prefix + security.token_urlsafe()
예제 #18
0
 def generate_access_token(self, oauth_request):
     return ACCESS_TOKEN_PREFIX + token_urlsafe()
예제 #19
0
 def generate_refresh_token(self, oauth_request):
     return REFRESH_TOKEN_PREFIX + token_urlsafe()
예제 #20
0
def test_token_urlsafe_no_args():
    tok = token_urlsafe()

    assert isinstance(tok, text_type)
    assert len(tok) > 32
예제 #21
0
 def _generate_token(self):
     return PREFIX + security.token_urlsafe()
예제 #22
0
 def _generate_token(self):
     return PREFIX + security.token_urlsafe()
예제 #23
0
    def __init__(self, **kwargs):
        super(Token, self).__init__(**kwargs)
        self.regenerate()

        if self.expires:
            self.refresh_token = security.token_urlsafe()