This commit is contained in:
Karol Wypchlo 2021-02-22 17:06:32 +01:00
parent 2ccfcb5751
commit 76f1dbb16a
4 changed files with 42 additions and 13 deletions

View File

@ -66,7 +66,7 @@
preserve_host: true
url: "http://accounts:3000"
match:
url: "http://oathkeeper<{,:4455}>/<{user,user/**,login,logout}>"
url: "http://oathkeeper<{,:4455}>/<{user,user/**,square/**,login,logout}>"
methods:
- GET
- POST
@ -76,6 +76,10 @@
handler: allow
mutators:
- handler: id_token
- handler: header
config:
headers:
X-User: "{{ print .Subject }}"
errors:
- handler: redirect
config:

View File

@ -76,18 +76,11 @@ mutators:
noop:
enabled: true
# hydrator:
# enabled: true
# config:
# api:
# url: http://dashboard:3000/api/hydrator
# cookie:
# enabled: true
# config:
# cookies:
# user: "{{ print .Subject }}"
# some-arbitrary-data: "{{ print .Extra.foo }}"
header:
enabled: true
config:
headers:
X-User: "{{ print .Subject }}"
id_token:
enabled: true

View File

@ -16,6 +16,7 @@
"dayjs": "^1.10.4",
"express-jwt": "^6.0.0",
"formik": "^2.2.6",
"http-status-codes": "^2.1.4",
"jwks-rsa": "^1.12.2",
"ky": "0.25.1",
"next": "^10.0.6",
@ -25,6 +26,7 @@
"react": "17.0.1",
"react-dom": "17.0.1",
"skynet-js": "^3.0.0",
"square": "^8.1.1",
"superagent": "^6.1.0",
"swr": "^0.4.1",
"tailwindcss": "^2.0.3",

View File

@ -0,0 +1,30 @@
import { Client, Environment } from "square";
import { StatusCodes } from "http-status-codes";
const client = new Client({
environment: Environment.Sandbox,
accessToken: process.env.SQUARE_ACCESS_TOKEN,
});
const api = {
GET: async (req, res) => {
console.log(req.headers);
try {
const { result } = await client.customersApi.retrieveCustomer("R7R0NY1Z8WT11D43564EEFKTYR");
res.json(result?.customer?.cards ?? []);
} catch (error) {
// console.log(error);
res.json([]);
}
},
};
export default (req, res) => {
if (req.method in api) {
api[req.method](req, res);
} else {
res.status(StatusCodes.NOT_FOUND);
}
};