# How to generate nonce from client-side Javascript

**URL:** <https://meta.discourse.org/t/how-to-generate-nonce-from-client-side-javascript/69767>\
**Category:** Development\
**Created:** [10 Settembre 2017, 9:52pm UTC](https://meta.discourse.org/t/how-to-generate-nonce-from-client-side-javascript/69767 "2017-09-10T21:52:56Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![ratebeer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ratebeer/32/120255_2.png) [@ratebeer](https://meta.discourse.org/u/ratebeer)\
**Post date:** [10 Settembre 2017, 9:52pm UTC](https://meta.discourse.org/t/how-to-generate-nonce-from-client-side-javascript/69767/1 "2017-09-10T21:52:56Z")

</div>

I am using `<script type="text/discourse-plugin" version="0.8.9">` in my instance’s `<head>` and it provides me access to the `api` object. What I can’t figure out however, is how to generate a nonce with it.

I’m detecting whether the visitor is logged into discourse or not, and whether they have a special cookie from the rest of my (non-discourse) site which indicates they’re logged in. If these 2 conditions are met, I do some magic to auto-log them into discourse. So far I’ve got it all working, except I have no nonce with which to create the signature that discourse needs when the user is redirected back.  
With no nonce I get the error:

`Verbose SSO log: Nonce has already expired`

How can I use the api object to ensure a nonce gets generated for my auto-logins?

---

_[View the full topic](https://meta.discourse.org/t/how-to-generate-nonce-from-client-side-javascript/69767)._
