<script>
if (document.location.hash) {
var parsedHash = new URLSearchParams(window.location.hash.substr(1));
if (parsedHash.get('access_token')) {
var access_token = parsedHash.get('access_token');
document.getElementById('access_token').textContent = 'Your Access Key from the #url: ' + access_token;
~snip~
Skip the new window stuff and just have a <a href="LinkToTwitchWithRedirectBack">
I have written a full implicit auth one pager here, that might help
It’s not for OIDC, but “regular” oAuth.
I’ve not played with OIDC via implicit myself, but it’s the same.
The only real difference is validating the JWT which you can’t exactly do client side anyway, since that needs the secret, which you shouldn’t leak publicly, but you’d pass that up to a server for validation if you need to.
You probably don’t even need OIDC here, just request with no scopes, and then use the code I’ve linked to get the user in Client Side code via JS fetch.
I’ve just managed to get your example working locally. Thank you so much.
I had never dealt with webservers before and after reading around chose to install XAMPP. With a few config changes i managed to redirect back to the html successfully. I see that when using 127.0.0.1 the redirect work and the fields are successfully populated. Out of curiosity i changed the dev console and local variable back to localhost as the TwitchAPI usually recommends and then it stopped working. The redirect worked but the fields were not populated.
I don’t really understand why this is, are you able to explain why? or have a resource that i can read in to so that i can better understand why the webserver is needed to test this as opposed to using localhost? I’m assuming it has to do with security, but wish to fully understand.
Thanks again for your help as from here, i can seek to understand it all better and then will be able to experiment more.
DaiReaver:
I don’t really understand why this is, are you able to explain why? or have a resource that i can read in to so that i can better understand why the webserver is needed to test this as opposed to using localhost? I’m assuming it has to do with security, but wish to fully understand.
localhost and 127.0.0.1 are the same thing. The example doesn’t work when running off file:// URL’s
But both need to be running off something that serves HTML on port 80, for http and port 443 for https (generally speaking). So it should work for localhost, assuming your localhost is configure correctly and nothing else is running that may grab it.
btw, talking about oauth, something happened with the login, at least on android with WebView.
Previously https://id.twitch.tv/oauth2... this would land you on the desktop site, but since Feb. 20, it lands you on a mobile site (with the option to Facebook login). If you login like that i will not land you on https://localhost#access_token, but on some other site, although you still get your access_token.
I have to explicitly request the desktop site, to get the results https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-implicit-code-flow described here.
Was this an intentional change? I can make a separate post on this if not.