Esempio n. 1
0
class ApplicationScope(BaseModel):
    __tablename__ = "application_scopes"

    application_id = db.Column(db.String(36), db.ForeignKey("applications.id"))
    scope_id = db.Column(db.String(36), db.ForeignKey("scopes.id"))
    scope_access = db.Column(
        db.Enum(ScopeAccess), nullable=False, default=ScopeAccess.NO_ACCESS
    )
    scope = db.relationship("Scope", back_populates="applications")
    application = db.relationship("Application", back_populates="scopes")
Esempio n. 2
0
class Role(BaseModel, RoleMixin):
    __tablename__ = "roles"

    name = db.Column(db.String(80), unique=True, nullable=False)
    description = db.Column(db.String(255))

    def __init__(self, name, description):
        super(Role, self).__init__()

        self.name = name
        self.description = description

    def __str__(self):
        return str(self.name)
Esempio n. 3
0
class AuthorizationCode(BaseModel):
    __tablename__ = "authorization_codes"

    code = db.Column(db.String(36), nullable=False, default=_get_uuid)
    expiry = db.Column(db.DateTime(), nullable=False)
    state = db.Column(db.String(36), nullable=False)
    user_id = db.Column(db.String(36), db.ForeignKey("users.id"))
    application_id = db.Column(db.String(36), db.ForeignKey("applications.id"))

    def __init__(self, expiry, state, user_id, application_id):
        self.expiry = expiry
        self.state = state
        self.user_id = user_id
        self.application_id = application_id
Esempio n. 4
0
class Scope(BaseModel):
    __tablename__ = "scopes"

    name = db.Column(db.String(80), unique=True, nullable=False)
    description = db.Column(db.String(255))
    applications = db.relationship("ApplicationScope", back_populates="scope")

    def __init__(self, name, description):
        super(Scope, self).__init__()

        self.name = name
        self.description = description

    def __str__(self):
        return str(self.name)
Esempio n. 5
0
class Application(BaseModel):
    __tablename__ = "applications"

    name = db.Column(db.String(), unique=True, nullable=False)
    description = db.Column(db.String())
    redirect_uri = db.Column(db.String(), nullable=False)
    client_id = db.Column(db.String(36), nullable=False, default=_get_uuid)

    scopes = db.relationship("ApplicationScope", back_populates="application")

    def __init__(self, name, description, redirect_uri):
        super(Application, self).__init__()

        self.name = name
        self.description = description
        self.redirect_uri = redirect_uri

    def __str__(self):
        return str(self.name)
Esempio n. 6
0
class User(BaseModel, UserMixin):
    __tablename__ = "users"

    username = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    active = db.Column(db.Boolean(), default=True)
    roles = db.relationship(
        "Role", secondary="user_roles", backref=db.backref("users", lazy="dynamic")
    )
    authorized_applications = db.relationship(
        "Application",
        secondary="user_authorized_applications",
        backref=db.backref("users", lazy="dynamic"),
    )

    def __init__(self, username, password):
        super(User, self).__init__()

        self.username = username
        self.password = hash_password(password)

    def __str__(self):
        return str(self.username)
Esempio n. 7
0
class BaseModel(db.Model):
    __abstract__ = True

    id = db.Column(db.String(36),
                   nullable=False,
                   primary_key=True,
                   default=_get_uuid)
    created = db.Column(db.DateTime(), nullable=False, default=datetime.utcnow)
    updated = db.Column(db.DateTime(),
                        nullable=False,
                        default=datetime.utcnow,
                        onupdate=datetime.utcnow)
    deleted = db.Column(db.Boolean(), nullable=False, default=False)

    def __eq__(self, other):
        return str(self.id) == str(other.id)

    def __repr__(self):
        return str(self.id)
class UserAuthorizedApplication(BaseModel):
    __tablename__ = "user_authorized_applications"

    user_id = db.Column(db.String(36), db.ForeignKey("users.id"))
    application_id = db.Column(db.String(36), db.ForeignKey("applications.id"))