# SSO and e-mail addresses having a plus sign

**URL:** https://meta.discourse.org/t/sso-and-e-mail-addresses-having-a-plus-sign/98481
**Category:** Support
**Created:** [10월 1, 2018, 1:39오후 UTC](https://meta.discourse.org/t/sso-and-e-mail-addresses-having-a-plus-sign/98481 "2018-10-01T13:39:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![thabbs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thabbs/32/82150_2.png) [@thabbs](https://meta.discourse.org/u/thabbs)
#### Post date: [10월 1, 2018, 1:39오후 UTC](https://meta.discourse.org/t/sso-and-e-mail-addresses-having-a-plus-sign/98481/1 "2018-10-01T13:39:21Z")

</div>

I’m not sure if this is an implementation error on my side or if this is a bug in the SSO implementation of Discourse.  
Users having a plus-extension in the local part of their e-mail address got an error since Discourse interpretes the plus sign as space.

Following [Setup DiscourseConnect - Official Single-Sign-On for Discourse (sso)](https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045) I must not urlencode the payload before encoding it to base64.

Here my basic implementation, written in php:

```
$email = 'user+extension@example.com';
$payload = base64_encode($nonce. "&email={$email}&external_id={$external_id}&username={$realname}&name={$realname}");
$return_sig = hash_hmac('sha256', $payload, $token);
header("Location: $referer/session/sso_login?sso=". rawurlencode($payload) ."&sig=". $return_sig);

```

Discourse throws the error: “Nonce has already expired” and writes down the e-mail address as “user [extension@example.com](mailto:extension@example.com)” with a space instead of a plus sign.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [10월 2, 2018, 1:30오전 UTC](https://meta.discourse.org/t/sso-and-e-mail-addresses-having-a-plus-sign/98481/2 "2018-10-02T01:30:19Z")

</div>

> [@thabbs](#):
>
> base64\_encode($nonce.

You need `"nonce=" . $nonce.` there…

---

<div class="post-metadata">

### Author: ![thabbs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thabbs/32/82150_2.png) [@thabbs](https://meta.discourse.org/u/thabbs)
#### Post date: [10월 2, 2018, 7:30오전 UTC](https://meta.discourse.org/t/sso-and-e-mail-addresses-having-a-plus-sign/98481/3 "2018-10-02T07:30:30Z")

</div>

This is already there and was not the reason for my request.

```
(
    $nonce = base64_decode($sso);
    # starts with nonce=...
)

```

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [4월 14, 2021, 10:46오전 UTC](https://meta.discourse.org/t/sso-and-e-mail-addresses-having-a-plus-sign/98481/4 "2021-04-14T10:46:17Z")

</div>

조금 늦은 것 같습니다. 하지만 다른 분들도 같은 문제에 부딪히지 않도록 공유합니다.

> [@thabbs](#):
>
> [Discourse 공식 단일 로그인 (SSO)](https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045) 문서를 따르면, 페이로드를 base64로 인코딩하기 전에 urlencode를 해서는 안 됩니다.

사실 base64 인코딩 전에 페이로드를 urlencode해야 합니다. 저희 [워드프레스 플러그인](https://github.com/discourse/wp-discourse/blob/master/lib/sso-provider/sso.php#L87)과 [루비 구현](https://github.com/discourse/discourse/blob/master/lib/single_sign_on.rb#L129-L136) 모두 페이로드를 구성할 때 라이브러리 함수를 사용하며, 이 함수들이 인코딩을 자동으로 처리합니다.

문서를 더 명확하게 수정했습니다:

> [@sam](#):
>
> 1. 새로운 **URL 인코딩** 페이로드를 생성합니다

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [4월 21, 2021, 7:00오전 UTC](https://meta.discourse.org/t/sso-and-e-mail-addresses-having-a-plus-sign/98481/5 "2021-04-21T07:00:27Z")

</div>

이 주제는 6일 후 자동으로 닫혔습니다. 더 이상 새로운 답글을 작성할 수 없습니다.
