Hello, Stephanie, how are you doing? Hope you’re doing well, all things considered
I’ve found this article indeed and it seemed to be what I was looking for, 'til I reached the “Configure credentials” section because, as I said, it’s a static site, having such a file means nothing as what Hugo generates is HTML/CSS/JS and static files like images, fonts and etc.
If I could imagine a pseudo-code, it would be something like this (terminology used loosely, my apologies):
$( '#login_button' ).on( 'click', () => {
const auth0 = new Auth0({
"domain": "YOUR_DOMAIN",
"clientId": "YOUR_CLIENT_ID"
});
const auth = auth0.connect( 'github', {
identifier: `MY_GITHUB_SOCIAL_CONNECTION_ID`
});
if( auth ) {
/* Authorized, do something */
} else {
/* Not authorized, do something else */
}
});
So after clicking the login button visitor would be redirected to Auth0, then to Github, grant the Authorization (or not) then back to my page. Not really sure if that’s what actually happens, but I think you got my meaning.
But all I can find are examples based on NodeJS and alike but nothing for the “old-school” way. I don’t use NodeJS, I don’t even know if what Hugo generates can be used with NodeJS and even if they could be used together, in the end, the project will be hosted on Github Pages which is only HTML/CSS/JS and static files.
Thank you for your time
[EDIT]
I think I managed to make it work… in parts. Following the idea of the pseudo-code I imagined above I came up with this:
<script src="https://cdn.auth0.com/js/auth0/9.11/auth0.min.js"></script>
let auth = new auth0.WebAuth({
domain: DOMAIN,
clientID: CLIENT_ID,
redirectUri: CALLBACK_URL,
});
$( '#login' ).on( 'click', () => {
auth.authorize({
connection: 'github',
scope: 'email read:user user:follow notifications',
responseType: 'code',
returnTo: window.location.href
});
return false;
});
And, apparently, it’s working. I mean, I click the button, I’m redirected to the Github Authorization page and after authorized, I’m sent back to CALLBACK_URL/?code=<some_random_characters>&state=<more_random_characters>
— which I suppose are the information I’ll use to consume Github API, but I’m not sure yet — and when I check Github’s OAuth Apps I see 1 user
.
However, I have no ways to return to the page where the visitor (in this case, me, hehe) was at the moment the button was clicked.
After A LOT of reading and abstraction from React/NodeJS fragments I don’t understand a thing, apparently (and I confirmed in API docs later) I could add more parameters to the request (here represented by returnTo
) but such parameter isn’t being passed to Github Authorization Page nor to my callback page, like, perhaps, CALLBACK_URL/?code=<some_random_characters>&state=<more_random_characters>&returnTo=PREVIOUS_URL
Then I thought about using popups so, at least, visitors wouldn’t be redirected away from the page they were, but I couldn’t find a working snippet because every single one of them yielded me errors like “popup function is not defined”.
How should I proceed?