# Inlogfout bij het gebruik van Discourse als identiteitsprovider (SSO, DiscourseConnect)

**URL:** <https://meta.discourse.org/t/login-error-while-trying-to-use-discourse-as-an-identity-provider-sso-discourseconnect/266603>\
**Category:** SSO\
**Created:** [30 mei 2023 om 13:28 UTC](https://meta.discourse.org/t/login-error-while-trying-to-use-discourse-as-an-identity-provider-sso-discourseconnect/266603 "2023-05-30T13:28:38Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ygramoel](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@ygramoel](https://meta.discourse.org/u/ygramoel)\
**Post date:** [30 mei 2023 om 15:50 UTC](https://meta.discourse.org/t/login-error-while-trying-to-use-discourse-as-an-identity-provider-sso-discourseconnect/266603/3 "2023-05-30T15:50:23Z")

</div>

Got it: the HMAC-SHA256 signature must be computed from the base64 encoded data, not from the url encoded data. So the correct code is:

```plaintext
import secrets
import base64
import urllib.parse
import hmac
import hashlib

forum_url = 'https://forum.embeetle.com'
target_url = 'https://embeetle.com/#account'
sso_secret = b'JCLSVcqbAnEPXz2p2xBY'

nonce = secrets.token_urlsafe()
payload = f'nonce={nonce}&return_sso_url={target_url}'
payload_base64 = base64.b64encode(payload.encode('utf-8')).decode()
payload_for_url = urllib.parse.quote(payload_base64)

signature = hmac.new(
    sso_secret, payload_base64.encode('utf-8'), hashlib.sha256
).hexdigest()

print(f'{forum_url}/session/sso_provider?sso={payload_for_url}&sig={signature}')

```

Now for the rest of the work: handling the redirect, checking the nonce, etc. To be continued …

---

_[View the full topic](https://meta.discourse.org/t/login-error-while-trying-to-use-discourse-as-an-identity-provider-sso-discourseconnect/266603)._
