Example #1
0
class OAuth2DynamoToken(Model):
    """ Dynamo version of authlib.integrations.sqla_oauth2.OAuth2TokenMixin """
    __metadata__ = {
        'global_indexes': [
            GlobalIndex.keys('refresh-index', 'refresh_token').throughput(read=10, write=2),
            GlobalIndex.keys('user-index', 'user_id').throughput(read=10, write=2)
        ],
    }

    client_id = Field(type=STRING)
    user_id = Field(type=NUMBER)
    token_type = Field(type=STRING)
    access_token = Field(hash_key=True)
    refresh_token = Field(type=STRING)
    scope = Field()
    revoked = Field(type=bool)
    issued_at = Field(type=NUMBER)
    expires_in = Field(type=NUMBER)

    def get_client_id(self):
        return self.client_id

    def get_scope(self):
        return self.scope

    def get_expires_in(self):
        return self.expires_in

    def get_expires_at(self):
        return self.issued_at + self.expires_in

    def is_refresh_token_active(self):
        if self.revoked:
            return False
        expires_at = self.issued_at + self.expires_in * 2
        return expires_at >= time.time()
Example #2
0
class Store(Model):

    """ Test model for indexes """
    __metadata__ = {
        'global_indexes': [
            GlobalIndex.all('name-index', 'name', 'city'),
            GlobalIndex.keys('name-emp-index', 'name', 'num_employees'),
            GlobalIndex.include('name-profit-index', 'name', 'monthly_profit',
                                includes=['name', 'num_employees']),
        ],
    }
    city = Field(hash_key=True)
    name = Field(range_key=True)
    sq_feet = Field(data_type=int).all_index('size-index')
    num_employees = Field(data_type=int).keys_index('emp-index')
    monthly_profit = Field(data_type=float)\
        .include_index('profit-index', ['name', 'num_employees'])