Browse Source

Swagger documentation for authorization API

Ref #24
feature/29
Martin Bober 6 months ago
parent
commit
5b751b344b
  1. 126
      openapi.yaml
  2. 5
      swagger/Readme.md
  3. BIN
      swagger/favicon-16x16.png
  4. BIN
      swagger/favicon-32x32.png
  5. 16
      swagger/index.css
  6. 19
      swagger/index.html
  7. 79
      swagger/oauth2-redirect.html
  8. 20
      swagger/swagger-initializer.js
  9. 3
      swagger/swagger-ui-bundle.js
  10. 1
      swagger/swagger-ui-bundle.js.map
  11. 3
      swagger/swagger-ui-es-bundle-core.js
  12. 1
      swagger/swagger-ui-es-bundle-core.js.map
  13. 3
      swagger/swagger-ui-es-bundle.js
  14. 1
      swagger/swagger-ui-es-bundle.js.map
  15. 3
      swagger/swagger-ui-standalone-preset.js
  16. 1
      swagger/swagger-ui-standalone-preset.js.map
  17. 4
      swagger/swagger-ui.css
  18. 1
      swagger/swagger-ui.css.map
  19. 2
      swagger/swagger-ui.js
  20. 1
      swagger/swagger-ui.js.map

126
openapi.yaml

@ -0,0 +1,126 @@
openapi: 3.0.0
info:
title: "Pen&PaperBox API"
version: 1.0.0
servers:
- url: http://localhost:3000/api
description: Local development sever
- url: https://penpaperbox.com/api
description: Production server
components:
securitySchemes:
bearer:
type: http
scheme: bearer
description: Bearer token that can be obtained via `/1.0/login`
security:
- bearer: [ ]
paths:
/1.0/login:
post:
tags:
- "Authorization"
description: Generates a bearer token to be used in the `Authorization` header to authenticate the client.
parameters:
- name: responseType
in: query
required: true
description: Must be set to `token`
example: token
schema:
type: string
- name: client_id
in: query
required: true
description: Will be ignored
schema:
type: string
- name: state
in: query
description: Can be provided and will be included in response in order to associate the response with the request
schema:
type: string
requestBody:
content:
'application/json':
schema:
type: object
required:
- user_name
- password
properties:
user_name:
type: string
description: The player's email address
example: "bob@example.com"
password:
type: string
description: Player's password
responses:
200:
description: New token was issued
content:
'application/json':
schema:
type: object
properties:
access_token:
type: string
description: The bearer token you can use in the `Authorization` header to authenticate as this user
example: bearer
token_type:
type: string
expires_in:
type: integer
description: Number of seconds until the token expires
example: 2592000
state:
type: string
description: The state provided in the request if any.
400:
description: Invalid credentials
content:
'application/json':
schema:
type: object
properties:
error:
type: string
description: Error string according to RFC6749
example: "access_denied"
error_description:
type: string
description: Human-readable description of the error
example: "Invalid email/password combination"
state:
type: string
description: The state provided in the request if any.
/1.0/logout:
post:
tags:
- "Authorization"
description: Delete the currently used bearer token in the `Authorization` header, therefore performing a log out
responses:
200:
description: Access token was invalidated, therefore the session is logged out
content:
'application/json':
schema:
type: object
properties:
access_token:
type: string
description: The access token that was invalidated.
400:
description: An invalid token was provided.
content:
'application/json':
schema:
type: object
properties:
error:
type: string
description: Will be `invalid_token`
access_token:
type: string
description: The invalid access token you tried to invalidate

5
swagger/Readme.md

@ -0,0 +1,5 @@
# Swagger
This is a copy of the [Swagger] release `dist/` directory configured to serve the swagger documentation while development. Open [index.html](index.html) in your browser.
The actual OpenAPI file is at [../openapi.yaml](../openapi.yaml).

BIN
swagger/favicon-16x16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

BIN
swagger/favicon-32x32.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

16
swagger/index.css

@ -0,0 +1,16 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
background: #fafafa;
}

19
swagger/index.html

@ -0,0 +1,19 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
</body>
</html>

79
swagger/oauth2-redirect.html

@ -0,0 +1,79 @@
<!doctype html>
<html lang="en-US">
<head>
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}
arr = qp.split("&");
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value);
}
) : {};
isValid = qp.state === sentState;
if ((
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
});
}
if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg;
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
if (document.readyState !== 'loading') {
run();
} else {
document.addEventListener('DOMContentLoaded', function () {
run();
});
}
</script>
</body>
</html>

20
swagger/swagger-initializer.js

@ -0,0 +1,20 @@
window.onload = function() {
//<editor-fold desc="Changeable Configuration Block">
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
url: "../openapi.yaml",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
//</editor-fold>
};

3
swagger/swagger-ui-bundle.js

File diff suppressed because one or more lines are too long

1
swagger/swagger-ui-bundle.js.map

File diff suppressed because one or more lines are too long

3
swagger/swagger-ui-es-bundle-core.js

File diff suppressed because one or more lines are too long

1
swagger/swagger-ui-es-bundle-core.js.map

File diff suppressed because one or more lines are too long

3
swagger/swagger-ui-es-bundle.js

File diff suppressed because one or more lines are too long

1
swagger/swagger-ui-es-bundle.js.map

File diff suppressed because one or more lines are too long

3
swagger/swagger-ui-standalone-preset.js

File diff suppressed because one or more lines are too long

1
swagger/swagger-ui-standalone-preset.js.map

File diff suppressed because one or more lines are too long

4
swagger/swagger-ui.css

File diff suppressed because one or more lines are too long

1
swagger/swagger-ui.css.map

File diff suppressed because one or more lines are too long

2
swagger/swagger-ui.js

File diff suppressed because one or more lines are too long

1
swagger/swagger-ui.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save