Const SESSION_SECRET in node.js

Hi guys,

new to all this tech Twitch stuff so be gentle with me.

I am working through the basic example here:

https://github.com/TwitchDev/authentication-samples/tree/master/node

I have node.js running ok with a Hello World example
I have installed

iMac-Home:myapp1 franceswarburton$ npm install express --save
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN app@1.0.0 No repository field.

  • express@4.16.2
    added 49 packages in 2.81s
    iMac-Home:myapp1 franceswarburton$ npm install passport
    npm WARN app@1.0.0 No repository field.

  • passport@0.4.0
    added 3 packages in 2.012s
    iMac-Home:myapp1 franceswarburton$ npm install --save handlebars
    npm WARN app@1.0.0 No repository field.

  • handlebars@4.0.11
    added 24 packages in 2.776s

I have the sample app with settings

TWITCH_CLIENT_ID = ‘xxx’;
const TWITCH_SECRET = ‘xxx+Ibf7P8=’;
const SESSION_SECRET = ‘TEST123’;
const CALLBACK_URL = ‘http://localhost:3000/auth/twitch/callback>’

I don’t see any documentation on where to find SESSION_SECRET so I guessed I create my own

my app throws error

module.js:557
throw err;
^

Error: Cannot find module ‘express-session’
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object. (/Users/franceswarburton/myapp1/index.js:14:22)
at Module._compile (module.js:660:30)
at Object.Module._extensions…js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)

What magical wizards am I not understating here guys.

Cheers

Steve Warby

The issue is not to do with the session secret variable, but that you’re requesting the express-session module which it can’t find. Are you sure you correctly downloaded all modules?

This is what is showing in the terminal window:

iMac-Home:myapp1 franceswarburton$ npm install express --save
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN app@1.0.0 No repository field.

express@4.16.2
added 49 packages in 2.81s
iMac-Home:myapp1 franceswarburton$ npm install passport
npm WARN app@1.0.0 No repository field.

passport@0.4.0
added 3 packages in 2.012s
iMac-Home:myapp1 franceswarburton$ npm install --save handlebars
npm WARN app@1.0.0 No repository field.

handlebars@4.0.11
added 24 packages in 2.776s

It shows packages added

each one shows:

npm WARN app@1.0.0 No repository field.

Is this the issue?

Use just npm install with no package name in the directory where package.json is, and it will install all the dependencies listed in package.json. If you didn’t use the file from that sample repo, check the list there. Generally everything you require should be npm installed.

Thanks 3ventic.

I didn’t have the package.json in the directory
I have the index.js running now,

Terminal window shows:

iMac-Home:myapp1 franceswarburton$ node index.js
Twitch auth sample listening on port 3000!

However when I use this in the browser

http://localhost:3000/auth/twitch/callback
I get the following error:

https://localhost/?error=redirect_mismatch&error_description=Parameter+redirect_uri+does+not+match+registered+URI&state=1xLTBSY9QYH5rC8B0UIDRw5n

The error here is “Parameter redirect_uri does not match registered URI”.

This means that the redirect URI you have saved to your application profile on dev.twitch.tv is different from the one you’re providing in the auth url as the callback.

You also did register and plug in a valid set of Twitch ClientID’s and secrets?

Thanks swiftyspiffy.

I changed the settings in my application and got the twitch popup ‘allow access’ etc.

However I get the following:

InternalOAuthError: Failed to obtain access token
at OAuth2Strategy._createOAuthError (/Users/franceswarburton/myapp1/node_modules/passport-oauth2/lib/strategy.js:379:17)
at /Users/franceswarburton/myapp1/node_modules/passport-oauth2/lib/strategy.js:166:45
at /Users/franceswarburton/myapp1/node_modules/oauth/lib/oauth2.js:191:18
at passBackControl (/Users/franceswarburton/myapp1/node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage. (/Users/franceswarburton/myapp1/node_modules/oauth/lib/oauth2.js:157:7)
at IncomingMessage.emit (events.js:165:20)
at endReadableNT (_stream_readable.js:1101:12)
at process._tickCallback (internal/process/next_tick.js:152:19)

The only thing I’m not clear on is :slight_smile:
const SESSION_SECRET = ‘TEST123’;

I see in the Twitch settings I see client secret and a button to create a new.

Is this what I create or do I find this somewhere ?

Is this the issue now ?

The docs are not really clear from a beginners point of view.

Cheers

Steve Warby

Yes

const TWITCH_CLIENT_ID = ‘MY CLIENT ID’;
const TWITCH_SECRET = ‘MY TWITCH SECRET’;
const SESSION_SECRET = ‘TEST123’; // Where does this come from ???
const CALLBACK_URL = ‘AS PER THE DOCS’;

The session secret is a value you come up with. For testing purposes you can put anything you want there.

The only link referencing this is here:

I changed my local browser to:

http://192.168.1.9:3000/auth/twitch/callback

But I still get the above error.

I have checked my client ID & Twitch secret are correct.

Any ideas ??

It looks like everything is installed into node.js okay:

iMac-Home:myapp1 franceswarburton$ npm ls --depth=0
twitch-auth-sample@1.0.0 /Users/franceswarburton/myapp1
├── express@4.16.2
├── express-session@1.15.6
├── handlebars@4.0.11
├── passport@0.3.2
├── passport-oauth@1.0.0
└── request@2.83.0

leave it as

http://127.0.0.1:3000/auth/twitch/callback

As theres where the express server is bound

image

Should be similar to your settings Twitch Side

Thanks barry,

I had created an extension ( this is my goal ) and not an app.

I have created an app now and get this in the browser:

Access Token zhis0exhjxXXXX
Refresh Token 4shdr3tyjncll34lj6mi93XXXX
Display Name toolfolks
Bio
Image https://static-cdn.jtvnw.net/user-default-pictures/49988c7b-57bc-4dee-bd4f-6df4ad215d3a-profile_image-300x300.jpg

Not sure where to go from here though.

Any step by step tutorials anywhere.

The next example on https://dev.twitch.tv/get-started is a chat example.

Buy no docs on how I implement this.

I presume I create an HTML document ( as per the example ) but what next.

  1. Where do I upload the files.
  2. Do I have to use the authentication and pass this to the chat app?

I may be being dumb here but the docs seem to presume you know the whole process.

Cheers

Steve Warby

Theres the options you need under Settings → General

For testing an extension you can just serve the via Express.