Skip to content

Commit

Permalink
[PS-58] Add Fakebook oAuth window for the oAuth endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyDotWS committed Oct 26, 2024
1 parent 7943aeb commit 7641742
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 31 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ FROM node:20-alpine

WORKDIR /app
RUN npm install -g @mockoon/cli
COPY facebook-mock-api.json /app/
COPY index.html /app/
COPY . /app/
EXPOSE 3000

CMD ["mockoon-cli", "start", "--data", "/app/facebook-mock-api.json", "--port", "3000"]
38 changes: 9 additions & 29 deletions facebook-mock-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@
"statusCode": 200,
"label": "",
"headers": [],
"bodyType": "INLINE",
"filePath": "",
"bodyType": "FILE",
"filePath": "oauth.html",
"databucketID": "",
"sendFileAsBody": false,
"sendFileAsBody": true,
"rules": [
{
"target": "query",
Expand All @@ -363,19 +363,14 @@
"fallbackTo404": false,
"default": false,
"crudKey": "id",
"callbacks": [
{
"uuid": "86576dba-774c-4cbd-b55b-bfd08e3a3d87",
"latency": 0
}
]
"callbacks": []
},
{
"uuid": "0d44a409-56c4-4ca5-ab72-f36bd9a8f4fa",
"body": "{\n \"error\": \"State query param not provided\"\n}",
"uuid": "bdcd8528-8046-4917-b578-5d45861288fa",
"body": "{\n \"error\": \"Numeric state query paramater not provided\"\n \"example\": \"?state=1234567\"\n}",
"latency": 0,
"statusCode": 422,
"label": "",
"label": "State query paramater not provided",
"headers": [],
"bodyType": "INLINE",
"filePath": "",
Expand Down Expand Up @@ -501,23 +496,8 @@
"id": "2q0d",
"name": "New data",
"documentation": "",
"value": "[\n]"
"value": "[\n {\"id\": \"75adb32f-f92b-44ff-9a29-ca28fac17e50\", \"message\": \"test\"},\n {\"id\": \"f220d0a9-0d43-4224-a0bb-4b1553c89643\", \"message\": \"hello\"}\n]"
}
],
"callbacks": [
{
"uuid": "86576dba-774c-4cbd-b55b-bfd08e3a3d87",
"id": "n7x2",
"uri": "https://clementine.postsuite.xyz/connections/callback?code={{faker 'number.int' min=10 max=100000000}}&state={{queryParam 'state'}}",
"name": "Callback",
"documentation": "oAuth callback ",
"method": "get",
"headers": [],
"bodyType": "INLINE",
"body": "",
"databucketID": "",
"filePath": "",
"sendFileAsBody": true
}
]
"callbacks": []
}
85 changes: 85 additions & 0 deletions oauth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OAuth Provider - Authorization</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f4f8;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
color: #444;
}
.container {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
padding: 30px;
text-align: center;
width: 300px;
}
h1 {
font-size: 24px;
margin-bottom: 10px;
color: #007bff;
}
p {
font-size: 16px;
margin-bottom: 20px;
}
button {
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
padding: 10px 20px;
cursor: pointer;
transition: background-color 0.3s;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
footer {
margin-top: 20px;
font-size: 12px;
color: #888;
}
</style>
</head>
<body>
<div class="container">
<h1>Fakebook oAuth Window</h1>
<p>Hi John Smith,<br><br>Click to link your Fakebook account to <b>PostSuite</b>.<br><br>This will give permission to:<br>- Manage your page<br>- Post on your behalf</p>
<button id="redirectButton">Accept</button>
<footer>
&copy; 2024 Fakebook Inc
</footer>
</div>

<script>
document.addEventListener('DOMContentLoaded', () => {
const urlParams = new URLSearchParams(window.location.search);
const state = urlParams.get('state');
const token = "{{faker 'string.alphanumeric' 25}}"
const redirectUrl = 'https://clementine.postsuite.xyz/connections/callback';

// Set the button click event to redirect with the state parameter
document.getElementById('redirectButton').addEventListener('click', () => {
if (state) {
const redirectWithState = `${redirectUrl}?state=${encodeURIComponent(state)}&code=${encodeURIComponent(token)}`;
window.location.href = redirectWithState;
} else {
alert('State parameter is missing.');
}
});
});
</script>
</body>
</html>

0 comments on commit 7641742

Please sign in to comment.