diff --git a/exam/api/Login/Login.php b/exam/api/Login/Login.php index fdcd279..ed85fcd 100644 --- a/exam/api/Login/Login.php +++ b/exam/api/Login/Login.php @@ -33,7 +33,7 @@ class Login extends Api case "NotFound": throw ApiError::notFound("user"); case "Invalid": - throw ApiError::unauthorized("Invalid username or password"); + throw ApiError::notAllowed("Invalid username or password"); default: throw $err; } diff --git a/exam/api/Posts/Posts.php b/exam/api/Posts/Posts.php index 9c9da71..501eae3 100644 --- a/exam/api/Posts/Posts.php +++ b/exam/api/Posts/Posts.php @@ -60,7 +60,7 @@ class Posts extends Api $post = Post::getByID($id); // Throw 400 if we aren't admin but trying to edit another users post. - if (!$self->getIsAdmin() && $post->getUser()->getID() !== $self->getID()) throw ApiError::unauthorized("Not allowed"); + if (!$self->getIsAdmin() && $post->getUser()->getID() !== $self->getID()) throw ApiError::notAllowed("Not allowed"); // Try update. Response::json($post->update($content)); diff --git a/exam/api/Refresh/Refresh.php b/exam/api/Refresh/Refresh.php new file mode 100644 index 0000000..1c25796 --- /dev/null +++ b/exam/api/Refresh/Refresh.php @@ -0,0 +1,38 @@ +getMessage()) { + case "Failed": + throw ApiError::failed("Refresh failed"); + case "NotFound": + throw ApiError::unauthorized("Not authorized"); + default: + throw $err; + } + } + } +} diff --git a/exam/api/docs/api.yaml b/exam/api/docs/api.yaml index 034d5ef..ac669ce 100644 --- a/exam/api/docs/api.yaml +++ b/exam/api/docs/api.yaml @@ -310,6 +310,45 @@ paths: value: { "code": "NotFound", "entity": "post" } tags: - Post + /refresh: + post: + summary: Refresh + description: Token refresh. + security: + - BasicAuth: [] + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/RefreshRequest" + responses: + 200: + description: Success. + content: + application/json: + schema: + $ref: "#/components/schemas/LoginResponse" + 400: + description: Missing fields. + content: + application/json: + schema: + $ref: "#/components/schemas/MissingFieldResponse" + examples: + Missing fields: + value: { "code": "MissingField", "fields": ["refreshToken"] } + 500: + description: Failed. + content: + application/json: + schema: + $ref: "#/components/schemas/FailedResponse" + examples: + Failed: + value: { "code": "Failed", "message": "Refresh failed" } + tags: + - Refresh /register: post: summary: Register @@ -678,8 +717,7 @@ components: UnauthorizedResponse: type: object properties: - code: - type: Unauthorized + code: type:NotAllowed message: type: string FailedResponse: @@ -731,6 +769,8 @@ components: $ref: "#/components/schemas/UserResponse" token: type: string + refreshToken: + type: string UserResponse: type: object properties: @@ -855,6 +895,14 @@ components: properties: content: type: string + RefreshRequest: + type: object + required: + - refreshToken + properties: + refreshToken: + type: string + format: uuid4 securitySchemes: BasicAuth: type: apiKey @@ -864,4 +912,5 @@ tags: - name: Login/Logout - name: Post - name: Register + - name: Refresh - name: User diff --git a/exam/api/docs/index.html b/exam/api/docs/index.html index 30aa47b..e9199ff 100644 --- a/exam/api/docs/index.html +++ b/exam/api/docs/index.html @@ -384,7 +384,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ -

User not found.

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string"
}

Response samples

Content type
application/json
{
  • "user": {
    },
  • "token": "string"
}

Logout

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string"
}

Response samples

Content type
application/json
{
  • "user": {
    },
  • "token": "string",
  • "refreshToken": "string"
}

Logout

Log out user.

Authorizations:
BasicAuth

Responses

Request samples

Content type
application/json
{
  • "code": "string"
}

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

User

List users

Request samples

Content type
application/json
{
  • "code": "string"
}

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Refresh

Refresh

Token refresh.

+
Authorizations:
BasicAuth
Request Body schema: application/json
required
refreshToken
required
string <uuid4>

Responses

Request samples

Content type
application/json
{
  • "refreshToken": "string"
}

Response samples

Content type
application/json
{
  • "user": {
    },
  • "token": "string",
  • "refreshToken": "string"
}

User

List users

List all users.

Authorizations:
BasicAuth
query Parameters
p
integer >= 0
Default: 0

Current page.

@@ -482,7 +490,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU jYGAQp">

The number of items to return.

Responses

Response samples

Content type
application/json
{
  • "pages": 0,
  • "data": [
    ]
}

Get user

Response samples

Content type
application/json
{
  • "pages": 0,
  • "data": [
    ]
}

Get user

Get user by ID.

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

@@ -490,7 +498,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

Success.

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Update user

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Update user

Update user with ID.
Use special ID self to update logged in user.
Requires logged in user to have admin permissions for any ID other than self.

Authorizations:
BasicAuthBasicAuth
path Parameters
id
required
integer <int14>

User ID

@@ -500,7 +508,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

User not found.

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string",
  • "email": "string"
}

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Delete user

Request samples

Content type
application/json
{
  • "username": "string",
  • "password": "string",
  • "email": "string"
}

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Delete user

Delete user with ID.

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

@@ -508,7 +516,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

Success.

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Update user image

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Update user image

Update user image with ID.
Use special ID self to update logged in user.
Requires logged in user to have admin permissions for any ID other than self.

Authorizations:
BasicAuthBasicAuth
path Parameters
id
required
integer <int14>

User ID

@@ -518,7 +526,7 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

User not found.

Request samples

Content type
application/json
{
  • "image": "string",
  • "predefined": "string"
}

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Get user posts

Request samples

Content type
application/json
{
  • "image": "string",
  • "predefined": "string"
}

Response samples

Content type
application/json
{
  • "id": 0,
  • "username": "string",
  • "status": 0,
  • "email": "string",
  • "image": "string",
  • "isAdmin": true,
  • "memberSince": {
    },
  • "postCount": 0
}

Get user posts

Get a users posts ID.

Authorizations:
BasicAuth
path Parameters
id
required
integer <int14>

User ID

@@ -532,9 +540,9 @@ data-styled.g137[id="sc-kvXgyf"]{content:"fBvPoH,"}/*!sc*/ " class="sc-euGpHm sc-exayXG fwfkcU kqJXdD sc-dHrNzZ dRdjww">

Success.

Response samples

Content type
application/json
{
  • "pages": 0,
  • "data": [
    ]
}
+

Response samples

Content type
application/json
{
  • "pages": 0,
  • "data": [
    ]
}