Discourse as an identity provider not working in localhost

I set up discourse locally. now i am trying to use discourse as identity provider. i followed this guide

but i am getting error

GET http://localhost:3000/session/sso_provider?sso=bm9uY2U9MWc3NlQyaHRVZTZTYzJENjVEbzlzUT09JnJldHVybl9zc29fdXJsPWh0dHA6Ly9sb2NhbGhvc3Q6ODA4MS9yZWRpcmVjdA%3D%3D&sig=abcdb4a453080b7bac871d1d8d660bc731cfbc2a26fc6013f19a848c0018461c 422 (Unprocessable Entity)

Note: my client making request is on localhost and discourse server is on localhost as well.
I tried looking for similar questions online but could not find any help. I am also posting my node js code for reference

app.get('/login', (req, res) => {
  let nonce = crypto.randomBytes(16).toString('base64');
  const payload = `nonce=${nonce}&return_sso_url=http://localhost:8081/redirect`
  const base64 = Buffer.from(payload).toString('base64')
  const URL_ENCODED_PAYLOAD = encodeURIComponent(base64)
  let hmac = crypto.createHmac('sha256', 'myrandomstring')
  hmac.update(URL_ENCODED_PAYLOAD)
  let HEX_SIGNATURE = hmac.digest('hex').toLowerCase()
  res.redirect(`http://localhost:3000/session/sso_provider?sso=${URL_ENCODED_PAYLOAD}&sig=${HEX_SIGNATURE}`)
})

Can anyone please help me figure out why its not working? Thanks

I’m pretty sure that it requires https which doesn’t work on local host.

@pfaffman It works on localhost. Turns out an mistake from my end. but now i am facing an issue when i am redirected to discourse page i enter my username and password and click login but it does not redirect me back to my website. I read a similar post here Discourse doesn't redirect to return_sso_url after user logs in on private site - #4 by simon but they have fixed that issue for social logins (I guess not for username password auth). Can u help me about that? Thanks

1 Like