Skip to content

Commit

Permalink
fix: added all auth url in oathkeeper (#3299)
Browse files Browse the repository at this point in the history
* fix: added all auth url in ory

* fix: bats-test

* fix: response type in auth, consistent response 'res.send'

---------

Co-authored-by: Siddharth <[email protected]>
  • Loading branch information
siddhart1o1 and Siddharth authored Oct 6, 2023
1 parent ea0f1d3 commit dad1529
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/api/dev/ory/oathkeeper_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
upstream:
url: "http://bats-tests:4012"
match:
url: "<(http|https)>://<[a-zA-Z0-9-.:]+>/auth/<(clearCookies|login|logout|email/code|email/login|totp/validate|email/login/cookie)>"
url: "<(http|https)>://<[a-zA-Z0-9-.:]+>/auth/<(clearCookies|login|logout|email/code|email/login|totp/validate|email/login/cookie|phone/captcha|phone/code|phone/login)>"
methods: ["GET", "POST", "OPTIONS"]
authenticators:
- handler: anonymous
Expand Down
20 changes: 10 additions & 10 deletions core/api/src/servers/authorization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,23 +424,24 @@ authRouter.post("/email/login/cookie", async (req: Request, res: Response) => {

authRouter.post("/phone/captcha", async (req: Request, res: Response) => {
const result = await registerCaptchaGeetest()
if (result instanceof Error) return res.json({ error: "error creating challenge" })
if (result instanceof Error) {
return res.status(500).send({ error: "error creating challenge" })
}

const { success, gt, challenge, newCaptcha } = result

return {
return res.send({
result: {
id: gt,
challengeCode: challenge,
newCaptcha,
failbackMode: success === 0,
},
}
})
})

authRouter.post("/phone/code", async (req: Request, res: Response) => {
const ip = req.originalIp

const phoneRaw = req.body.phone
const challengeCodeRaw = req.body.challengeCode
const validationCodeRaw = req.body.validationCode
Expand All @@ -451,7 +452,7 @@ authRouter.post("/phone/code", async (req: Request, res: Response) => {
return res.status(400).send({ error: "missing inputs" })

const phone = checkedToPhoneNumber(phoneRaw)
if (phone instanceof Error) return res.status(400).send("invalid phone")
if (phone instanceof Error) return res.status(400).send({ error: "invalid phone" })

const geetestChallenge = challengeCodeRaw
const geetestValidate = validationCodeRaw
Expand All @@ -466,25 +467,24 @@ authRouter.post("/phone/code", async (req: Request, res: Response) => {
channel,
})

if (result instanceof Error) return res.status(400).json({ error: result })
if (result instanceof Error) return res.status(400).send({ error: result })

return res.json({
return res.send({
success: true,
})
})

authRouter.post("/phone/login", async (req: Request, res: Response) => {
const ip = req.originalIp

const codeRaw = req.body.code
const phoneRaw = req.body.phone
if (!codeRaw || !phoneRaw) {
return res.status(400).send({ error: "missing inputs" })
}
const code = validOneTimeAuthCodeValue(codeRaw)
if (code instanceof Error) return res.status(400).send("invalid code")
if (code instanceof Error) return res.status(400).send({ error: "invalid code" })
const phone = checkedToPhoneNumber(phoneRaw)
if (phone instanceof Error) return res.status(400).send("invalid phone")
if (phone instanceof Error) return res.status(400).send({ error: "invalid phone" })

const loginResp = await Authentication.loginWithPhoneToken({
phone,
Expand Down

0 comments on commit dad1529

Please sign in to comment.