# External SSO provider but discourse logs say None has already expired (please help!)

**URL:** <https://meta.discourse.org/t/external-sso-provider-but-discourse-logs-say-none-has-already-expired-please-help/176271>\
**Category:** SSO\
**Created:** [January 16, 2021, 8:38am UTC](https://meta.discourse.org/t/external-sso-provider-but-discourse-logs-say-none-has-already-expired-please-help/176271 "2021-01-16T08:38:40Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![James\_Hope](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_hope/32/204225_2.png) [@James\_Hope](https://meta.discourse.org/u/James_Hope)\
**Post date:** [January 17, 2021, 1:21pm UTC](https://meta.discourse.org/t/external-sso-provider-but-discourse-logs-say-none-has-already-expired-please-help/176271/4 "2021-01-17T13:21:20Z")

</div>

I am sharing the way that we generate the return url, to hopefully shed some more light on this problem:

```
   public String generateSSORedirectURL(String nonce, String email, String uid) {

    //generate the return payload
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("nonce", nonce);
    params.put("external_id",uid);
    params.put("email",email);
    params.put("username",email);
    params.put("require_activation","false");
    params.put("name",email);
    params.put("return_sso_url","https://discourse-site/session/sso_login");
    log.info("params {}", params);

    //prepare the return payload
    String encodedParams = params.keySet().stream()
        .map(key -> key + "=" + encodeValue(params.get(key)))
        .collect(Collectors.joining("&"));
    log.info("encoded parameters {}", encodedParams);

    String returnPayload = Base64.getEncoder().encodeToString(encodedParams.getBytes());
    log.info("return Payload {}", returnPayload);

    //calculate the hmacSha256 signature for the payload
    byte[] hmacSha256 = calcHmacSha256(ssoSecret.getBytes(), returnPayload.getBytes());
    log.info("hmacSha256 sig {}", hmacSha256);
    
    String hmacSha265Hex = String.format("%x", new BigInteger(1, hmacSha256));
    log.info("hmacSha256, sig in Hex {}", String.format("%x", new BigInteger(1, hmacSha256)));

    HashMap<String, String> params2 = new HashMap<String, String>();
    params2.put("sig", hmacSha265Hex);
    params2.put("sso", returnPayload);
    log.info("params2 {}", params);

    String encodedParams2 = params2.keySet().stream()
        .map(key -> key + "=" + encodeValue(params2.get(key)))
        .collect(Collectors.joining("&"));
    log.info("encoded parameters {}", encodedParams2);

    //build and return the query string
    String queryString = forumUrl + "session/sso_login?" + encodedParams2;
    log.info("queryString {}", queryString);

    return queryString;
}

```

---

_[View the full topic](https://meta.discourse.org/t/external-sso-provider-but-discourse-logs-say-none-has-already-expired-please-help/176271)._
