Reputation: 1087
I want to implement a Slack authentication with Passport.js + Firebase Cloud Function. But when I redirected URL, the forbidden error occurs.
The error:
Your client does not have permission to get URL /api/auth/slack?uid=XXXXXXXXXXX&redirectTo=http://localhost:3000 from this server.
The React code:
const slackAuthorizeURL = (uid) =>
`https://us-central1-xxxxxxxxx.cloudfunctions.net/api/auth/slack?uid=${uid}&redirectTo=${window.location.href}`
<a href={slackAuthorizeURL}>Sign in with Slack</a>
The Server code:
const express = require('express')
const session = require('express-session')
const app = express()
const allowedOrigins = [
'http://localhost:3000',
]
const allowCrossDomain = (req, res, next) => {
const origin = req.headers.origin
if (allowedOrigins.includes(origin)) {
res.header('Access-Control-Allow-Origin', origin)
}
res.header('Access-Control-Allow-Methods', 'GET,POST')
res.header('Access-Control-Allow-Headers', 'Content-Type')
next()
}
app.use(allowCrossDomain)
app.use(session({ secret: config.session.secret }))
const passport = require('passport')
app.use(passport.initialize())
app.use(passport.session())
app.get('/auth/slack', (req, res, next) => {
req.session.uid = req.query.uid
req.session.redirectTo = req.query.redirectTo
passport.authenticate('slack')(req, res, next)
})
I have already set up allUsers
to Cloud Functions Admin
on api in Google Cloud Platform.
Upvotes: 0
Views: 181
Reputation: 1087
I missed to set up allUsers to Cloud Functions Admin on api in Google Cloud Platform correctly.
Upvotes: 1