{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Gamned Authentication API"
  },
  "tags": [
    {
      "name": "Token"
    },
    {
      "name": "Me"
    }
  ],
  "paths": {
    "/token": {
      "post": {
        "tags": [
          "Token"
        ],
        "summary": "Request an access token",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Auth"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfull",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/AuthPasswordSuccessResponse"
                    },
                    {
                      "$ref": "#/components/schemas/AuthOthersSuccessResponse"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Not Authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Not Authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/jwt": {
      "post": {
        "tags": [
          "Token"
        ],
        "summary": "Request an access token from jwt token",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JwtAuth"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfull",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthPasswordSuccessResponse"
                }
              }
            }
          },
          "401": {
            "description": "Not Authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/me": {
      "get": {
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "tags": [
          "Me"
        ],
        "summary": "Request token information",
        "responses": {
          "200": {
            "description": "Successfull",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/MeUserSuccessResponse"
                    },
                    {
                      "$ref": "#/components/schemas/MeClientSuccessResponse"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "description": "Error code"
                    },
                    "message": {
                      "type": "string",
                      "description": "Error message"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Auth": {
        "type": "object",
        "required": [
          "grant_type",
          "client_id"
        ],
        "properties": {
          "grant_type": {
            "type": "string",
            "description": "Can be one of the following: client_credentials, password or refresh_token"
          },
          "client_id": {
            "type": "string",
            "description": "Needed for all grant types"
          },
          "client_secret": {
            "type": "string",
            "description": "Needed for all grant types except refresh_token"
          },
          "username": {
            "type": "string",
            "description": "If password chosen"
          },
          "password": {
            "type": "string",
            "description": "If password chosen"
          },
          "refresh_token": {
            "type": "string",
            "description": "If refresh_token chosen"
          }
        }
      },
      "JwtAuth": {
        "type": "object",
        "required": [
          "token"
        ],
        "properties": {
          "token": {
            "type": "string",
            "description": "jwt token"
          },
          "client_id": {
            "type": "string",
            "description": "Client ID"
          }
        }
      },
      "AuthPasswordSuccessResponse": {
        "type": "object",
        "properties": {
          "access_token": {
            "type": "string"
          },
          "expires_in": {
            "type": "integer"
          },
          "token_type": {
            "type": "string"
          },
          "scope": {
            "type": "string"
          },
          "refresh_token": {
            "type": "string"
          }
        }
      },
      "AuthOthersSuccessResponse": {
        "type": "object",
        "properties": {
          "access_token": {
            "type": "string"
          },
          "expires_in": {
            "type": "integer"
          },
          "token_type": {
            "type": "string"
          },
          "scope": {
            "type": "string"
          }
        }
      },
      "AuthErrorResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "MeUserSuccessResponse": {
        "type": "object",
        "properties": {
          "user_id": {
            "type": "string",
            "description": "User login"
          },
          "id": {
            "type": "integer",
            "description": "Internal user ID"
          },
          "username": {
            "type": "string",
            "description": "User login"
          },
          "first_name": {
            "type": "string",
            "description": "User first name"
          },
          "last_name": {
            "type": "string",
            "description": "User last name"
          },
          "scope": {
            "type": "string",
            "description": "User scopes (separated by space)"
          },
          "params": {
            "type": "string",
            "description": "User params (json format)"
          },
          "active": {
            "type": "string",
            "description": "1 if token is active / 0 if token is inactive"
          },
          "deleted": {
            "type": "string",
            "description": "1 if user is deleted / 0 if not"
          },
          "access_token": {
            "type": "string",
            "description": "Access token"
          }
        }
      },
      "MeClientSuccessResponse": {
        "type": "object",
        "properties": {
          "client_id": {
            "type": "string",
            "description": "Client ID"
          },
          "scope": {
            "type": "string",
            "description": "Client scopes (separated by space)"
          },
          "params": {
            "type": "string",
            "description": "Client params (json format)"
          },
          "access_token": {
            "type": "string",
            "description": "Access token"
          }
        }
      }
    }
  }
}