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*/
-{- "username": "string",
- "password": "string"
}{- "user": {
- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}, - "token": "string"
}{- "username": "string",
- "password": "string"
}{- "user": {
- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}, - "token": "string",
- "refreshToken": "string"
}{- "code": "string"
}{- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}{- "code": "string"
}{- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}Token refresh.
+| refreshToken required | string <uuid4> |
{- "refreshToken": "string"
}{- "user": {
- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}, - "token": "string",
- "refreshToken": "string"
}List all users.
| 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. |
{- "pages": 0,
- "data": [
- {
- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}
]
}{- "pages": 0,
- "data": [
- {
- "id": 0,
- "username": "string",
- "status": 0,
- "email": "string",
- "image": "string",
- "isAdmin": true,
- "memberSince": {
- "date": "2019-08-24T14:15:22Z",
- "timezone_type": 0,
- "timezone": "string"
}, - "postCount": 0
}
]
}Get user by ID.