PAYW Authentication centralizes and simplifies
the sign up/login process of every PAYW service.
PAYW Auth uses JSON Web Tokens to authenticate user identity.
https://auth.payw.org/google/sign-up/:serviceName
https://auth.payw.org/verify
Field | Value |
---|---|
Authorization |
Bearer {accessToken} |
200
{
userID: number,
iat: number,
exp: number
}
401 (Unauthorized)
null
// or
{
expired: true
}
https://auth.payw.org/refresh
Field | Value |
---|---|
Authorization |
Bearer {refreshToken} |
200
{
accessToken: string
}
401 (Unauthorized)
null
Remove the previous refresh token and re-sign the new refresh token.
https://auth.payw.org/revoke
Field | Value |
---|---|
Authorization |
Bearer {refreshToken} |
200
{
refreshToken: string
}
401 (Unauthorized)
null
It is a module which includes several helper methods and most importantly automates the authentication process by following the flow below.
- Verify the access token.
- If unauthorized, return
false
. - If authorized, return the 200 response of Verify Access Token.
- If the access token has expired, try to refresh the access token using the refresh token.
- If unauthorized, return
false
. - If authorized, override the access token in cookie then go back to the first stage and verify again with the new token.
- If unauthorized, return
- If unauthorized, return
If you don't use the PAYW Auth Client, you have to manually implement this flow by yourself.
Node.js
npm install @payw/auth
import { PAYWAuth } from '@payw/auth'
const paywAuth = PAYWAuth(req, res)
paywAuth.verify().then((result) => {
// Do something
})
import { PAYWAuth } from '@payw/auth'
const paywAuth = PAYWAuth(req, res)
Deprecated. Use
storeTokens
instead.
Store access token and refresh token in httpOnly cookies.
paywAuth.storeTokens({ accessToken: '', refreshToken: '' })
Verify the tokens through the PAYW Authentication server.
paywAuth.verify()
Redirect to the given location.
paywAuth.redirect('/')
Get the sign up/login URL of a service.
import { PAYWAuth, getLoginURL } from '@payw/auth'
const paywAuth = PAYWAuth(req, res)
paywAuth.redirect(getLoginURL('saying.today'))
It's available in the browsers.