Get channel name after login on website

Hi guys,

what I want to do is:

create a website in which you press login with twitch, you do the login, he gives me back your channel username and if your username is my sub, then you see a content, otherwise not.
Basically a very simple website to create a very simple sub page.

I am using Angular for the website and I just tried to do:

< a href=“https://api.twitch.tv/kraken/oauth2/authorize?response_type=code
&client_id=[CLIENTID]
&redirect_uri=http://localhost:4200
&scope=user_read”>
Click to login with Twitch

It works and it sets the twitch cookie with my username and everything is good.
The problem is that I cannot get this cookie from my website, because this is from twitch.

So how can I do this? Is there a way to get an answer with the username and then make a call to see if he is my sub?

You need to complete steps 2 and 3

About step 2,

what I get back is:

http://localhost:4200/?code=[CODE]&scope=user_read

is this correct?

Yup, then you take that code and post (step 3) to get an access token (step 4) and then use the access token

ok but how do I use this to check if A is sub of me?

You do oAuth with channel_subscribers scope for yourself and thne use the subscriber end points

ok and what if I do not have a server?
I mean, I’m just using Angular client side, so where do I do the server part?

If you don’t have a server, then how do you intend to allow users to login?

I don’t need to store users. I just want to check if A is sub of me, if it is so, I show a certain page to him, otherwise not.
I don’t want to store anything

Then your code needs to be accessible from the internet, which means you need a server.

I just sent a private message to you, check it if you can.

Anyways, I wanted to do all of the website in Angular, then upload it via FTP to a domain

That is a server.

If you want to do this without leaking private keys, it is difficult to do it in pure client side code and users would be hesitant to grant access to their subscriptions (since the normal method is to do channel->user rather than user->channel)

Ok so how can I do this? That’s a server but when I usually upload code I just upload the HTML / Angular part without taking care of other if I don’t need to store or something like that.
So how can I do the POST part mentioned in step 3)?
Can I do that from the angular code?

I’m not 100% familiar with angular. I believe it’s pure client side, which means it’ll leak your secrets.

Pure client side will limit you to Implicit auth instead

And you’d have to get permission from the user to see ALL the users subscriptions.

And this endpoint

Implicit auth will allow you to just only use a ClientID

Barry, I think I am missing something.

Using the Implicit, I get back this:

https://localhost#access_token=0123456789abcdefghijABCDEFGHIJ
    &scope=viewing_activity_read
    &state=c3ab8aa609ea11e793ae92361f002671
    &token_type=bearer

So how can I use this to check if A is my sub?
I obviously have MY client ID but I have not the one of the person who is logging, right?

If the call is this
GET https://api.twitch.tv/kraken/users/<user ID>/subscriptions/<channel ID>
I need to know both user ids

Take the access_token and call

or you can call

Which’ll give you the user_id

You know YOUR channelID as it’s yours.

Ok, if I do

curl -H “Authorization: OAuth [OAUTH]” https://id.twitch.tv/oauth2/validate

with the OAUTH that I get with the implicit, it gives me back:

{“client_id”:“dagadgadfkjgnajkng”,“login”:“username”,“scopes”:[“viewing_activity_read”],“user_id”:“83749274932”}

This is what I want.
But I did this with curl, so how can I make this same request via javascript?
Angular uses javascript

  • fetch
  • jquery ajax
  • whateever angular does internally for http requests

can you help me with it? I am trying but I am not sure I am doing the right thing.

Actually I want to simulate what curl does inside my terminal, but from Angular using Javascript.
I have seen some ways to convert curl into node.js, python and more, but it is not the same, since I am using Typescript.

How would you convert that curl into an HTTP Request via Javascript?
If I do that, I think I’m done

I think this will help.

https://docs.angularjs.org/api/ng/service/$http