mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #1146 from omnivore-app/feature/android-apple-login-redirect
Android Apple Login Endpoint
This commit is contained in:
commit
dfea982df7
2 changed files with 20 additions and 5 deletions
|
|
@ -41,8 +41,7 @@ async function fetchApplePublicKey(kid: string): Promise<string | null> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function decodeAppleToken(
|
export async function decodeAppleToken(
|
||||||
token: string,
|
token: string
|
||||||
isWeb?: boolean
|
|
||||||
): Promise<DecodeTokenResult> {
|
): Promise<DecodeTokenResult> {
|
||||||
const decodedToken = jwt.decode(token, { complete: true })
|
const decodedToken = jwt.decode(token, { complete: true })
|
||||||
const { kid, alg } = (decodedToken as any).header
|
const { kid, alg } = (decodedToken as any).header
|
||||||
|
|
@ -54,8 +53,8 @@ export async function decodeAppleToken(
|
||||||
}
|
}
|
||||||
const jwtClaims: any = jwt.verify(token, publicKey, { algorithms: [alg] })
|
const jwtClaims: any = jwt.verify(token, publicKey, { algorithms: [alg] })
|
||||||
const issVerified = (jwtClaims.iss ?? '') === appleBaseURL
|
const issVerified = (jwtClaims.iss ?? '') === appleBaseURL
|
||||||
const audVerified =
|
const audience = jwtClaims.aud ?? ''
|
||||||
(jwtClaims.aud ?? '') === isWeb ? webAudienceName : audienceName
|
const audVerified = audience == webAudienceName || audience === audienceName
|
||||||
if (issVerified && audVerified && jwtClaims.email) {
|
if (issVerified && audVerified && jwtClaims.email) {
|
||||||
return {
|
return {
|
||||||
email: jwtClaims.email,
|
email: jwtClaims.email,
|
||||||
|
|
@ -106,7 +105,7 @@ export async function handleAppleWebAuth(
|
||||||
|
|
||||||
return env.client.url
|
return env.client.url
|
||||||
}
|
}
|
||||||
const decodedTokenResult = await decodeAppleToken(idToken, true)
|
const decodedTokenResult = await decodeAppleToken(idToken)
|
||||||
const authFailedRedirect = `${baseURL()}/login?errorCodes=${
|
const authFailedRedirect = `${baseURL()}/login?errorCodes=${
|
||||||
LoginErrorCode.AuthFailed
|
LoginErrorCode.AuthFailed
|
||||||
}`
|
}`
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ import {
|
||||||
createMobileEmailSignUpResponse,
|
createMobileEmailSignUpResponse,
|
||||||
} from './sign_up'
|
} from './sign_up'
|
||||||
import { createMobileAccountCreationResponse } from './account_creation'
|
import { createMobileAccountCreationResponse } from './account_creation'
|
||||||
|
import { env } from '../../../env'
|
||||||
|
import { corsConfig } from '../../../utils/corsConfig'
|
||||||
|
import cors from 'cors'
|
||||||
|
|
||||||
export function mobileAuthRouter() {
|
export function mobileAuthRouter() {
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
@ -60,5 +63,18 @@ export function mobileAuthRouter() {
|
||||||
res.status(payload.statusCode).json(payload.json)
|
res.status(payload.statusCode).json(payload.json)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Required since this will be called from Android WebView
|
||||||
|
router.options(
|
||||||
|
'/android-apple-redirect',
|
||||||
|
cors<express.Request>({ ...corsConfig, maxAge: 600 })
|
||||||
|
)
|
||||||
|
|
||||||
|
router.post('/android-apple-redirect', (req, res) => {
|
||||||
|
const { id_token } = req.body
|
||||||
|
return res.redirect(
|
||||||
|
`${env.client.url}/android-apple-token?token=${id_token as string}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue