Authentication tool for Fastberry
python -m pip install fbauth
add file /config/.env/development.toml
[env]
SECRET_KEY = "fastapi-insecure-09d25e094faa6ca2556c"
python manage.py db auto-migrate
python manage.py create-user --super --username admin --password secret --email admin@example.com
python manage.py create-user --super -u admin -p secret -e admin@example.com
config file /config/public-perms.json
{
"perms": ["UserCreate", "UserLogin", "UserMe"]
}
config file /config/spoc.toml
# [spoc] ...
[spoc.extras]
middleware = ["fbauth.middleware.AuthenticatedCookieMiddleware"]
extensions = ["fbauth.extension.InjectUser"]
permissions = ["fbauth.permissions.IsAuthorized"]
# User
mutation UserCreate {
UserCreate(
form: {
password: "my-secret-password"
username: "John-Doe"
email: "johndoe@example.com"
}
) {
... on User {
...UserFields
}
... on Error {
...ErrorFields
}
}
}
mutation UserLogin {
UserLogin(
username: null
email: "johndoe@example.com"
password: "my-secret-password"
) {
... on AccessToken {
token
tokenType
}
... on Error {
...ErrorFields
}
}
}
mutation AdminLogin {
UserLogin(username: "admin", password: "secret") {
... on AccessToken {
token
tokenType
}
... on Error {
...ErrorFields
}
}
}
mutation UserUpdate {
UserUpdate(form: { password: null, email: null, username: "John-Doe" }) {
... on User {
...UserFields
}
... on Error {
...ErrorFields
}
}
}
mutation UserRefreshToken {
UserRefreshToken(token: null) {
token
tokenType
}
}
mutation UserDisable {
UserDisable(state: false)
}
query UserMe {
UserMe {
...UserFields
}
}
query UserDetail {
UserDetail(id: "MTo6YTU1ZTUzMmVhYjAyOGI0Mg==") {
...UserFields
}
}
# Roles
query AllRoles {
RoleAll {
id
name
perms
}
}
mutation CreateRole {
RoleCreate(form: { name: "enduser", perms: null }) {
... on Role {
id
name
perms
}
... on Error {
...ErrorFields
}
}
}
mutation UpdateRole {
RoleUpdate(
form: {
id: "MTo6YTU1ZTUzMmVhYjAyOGI0Mg=="
name: "manager"
perms: ["AllRoles"]
}
) {
... on Role {
id
name
perms
}
... on Error {
...ErrorFields
}
}
}
mutation DeleteRole {
RoleDelete(id: "MTo6YTU1ZTUzMmVhYjAyOGI0Mg==")
}
# Reusable
fragment ErrorFields on Error {
error
meta
messages {
field
text
type
}
}
fragment UserFields on User {
id
username
email
password
isDisabled
isStaff
isSuperUser
isAuthenticated
isAnonymous
createdOn
role {
id
name
perms
}
}