Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoginNexus #1757

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8525b65
ServerAuth.js
Thebloxers998 Nov 23, 2024
9e61d03
The icon icon
Thebloxers998 Nov 23, 2024
ac53d15
Update ServerAuth.js
Thebloxers998 Nov 23, 2024
67f80c0
build(deps-dev): bump espree from 9.6.1 to 10.3.0
dependabot[bot] Nov 23, 2024
d66d76d
Update ServerAuth.js
Thebloxers998 Nov 23, 2024
9faa1ce
Update ServerAuth.js
Thebloxers998 Nov 23, 2024
b3cb528
Merge pull request #1 from Thebloxers998/dependabot/npm_and_yarn/espr…
Thebloxers998 Nov 23, 2024
7b9008a
E
Thebloxers998 Nov 23, 2024
eb3a4c9
E
Thebloxers998 Nov 23, 2024
8a9acdb
Update extensions.json
Thebloxers998 Nov 24, 2024
6bdf165
Update ServerAuth.js
Thebloxers998 Nov 24, 2024
587fce9
Update ServerAuth.js
Thebloxers998 Nov 24, 2024
c5c6ba3
Update ServerAuth.js
Thebloxers998 Nov 24, 2024
4ee06a8
E
Thebloxers998 Nov 24, 2024
fb82189
Revert "build(deps-dev): bump espree from 9.6.1 to 10.3.0"
Thebloxers998 Nov 25, 2024
0e41ebb
Merge pull request #2 from Thebloxers998/revert-1-dependabot/npm_and_…
Thebloxers998 Nov 25, 2024
5b128cb
Merge branch 'TurboWarp:master' into master
Thebloxers998 Nov 25, 2024
3ae4269
Update ServerAuth.js
Thebloxers998 Nov 25, 2024
0ccef2a
build(deps-dev): bump espree from 9.6.1 to 10.3.0
dependabot[bot] Nov 25, 2024
6f48215
Merge pull request #3 from Thebloxers998/dependabot/npm_and_yarn/espr…
Thebloxers998 Nov 26, 2024
e030f29
Merge branch 'TurboWarp:master' into master
Thebloxers998 Nov 26, 2024
c23a816
Update ServerAuth.js
Thebloxers998 Nov 26, 2024
1f770a4
Update ServerAuth.js
Thebloxers998 Nov 30, 2024
980aff7
Merge branch 'TurboWarp:master' into master
Thebloxers998 Nov 30, 2024
c75c4e9
"I, AM STEVE" 🔥🗣🗣
Thebloxers998 Nov 30, 2024
7bb4981
build(deps-dev): bump eslint from 9.15.0 to 9.16.0
dependabot[bot] Dec 3, 2024
bad5dda
build(deps-dev): bump prettier from 3.3.3 to 3.4.1
dependabot[bot] Dec 3, 2024
26c8a65
Uses 2 HTTP servers, 1 for authentication, 1 for registration
Thebloxers998 Dec 3, 2024
37d6c2b
Update LoginNexus.js
Thebloxers998 Dec 4, 2024
4e17fdb
Update LoginNexus.js
Thebloxers998 Dec 8, 2024
d9cf2e3
Update LoginNexus.js
Thebloxers998 Dec 9, 2024
79097c4
Fix LoginNexus.js
Thebloxers998 Dec 9, 2024
b209395
Merge branch 'TurboWarp:master' into master
Thebloxers998 Dec 9, 2024
96c3c5e
Merge pull request #5 from Thebloxers998/dependabot/npm_and_yarn/pret…
Thebloxers998 Dec 9, 2024
9179cba
Merge pull request #4 from Thebloxers998/dependabot/npm_and_yarn/esli…
Thebloxers998 Dec 9, 2024
15f34da
Update LoginNexus.js
Thebloxers998 Dec 9, 2024
dce2f9f
build(deps): bump express from 4.21.1 to 4.21.2
dependabot[bot] Dec 10, 2024
97aeee4
build(deps-dev): bump prettier from 3.4.1 to 3.4.2
dependabot[bot] Dec 10, 2024
d07cb61
Update LoginNexus.js
Thebloxers998 Dec 11, 2024
f602cf7
Merge pull request #6 from Thebloxers998/dependabot/npm_and_yarn/expr…
Thebloxers998 Dec 14, 2024
112fc8e
Merge pull request #7 from Thebloxers998/dependabot/npm_and_yarn/pret…
Thebloxers998 Dec 14, 2024
d59bdbe
Merge branch 'TurboWarp:master' into master
Thebloxers998 Dec 14, 2024
724f274
Merge branch 'TurboWarp:master' into master
Thebloxers998 Dec 16, 2024
5174267
Update LoginNexus.js
Thebloxers998 Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 284 additions & 0 deletions extensions/LoginNexus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
// Name: LoginNexus
// ID: loginNexus
// Description: A API-based authentication and registration extension
// By: Thebloxers998 <https://scratch.mit.edu/users/Thebloxers998/>
// License: MPL-2.0

(function(Scratch) {
'use strict';

class LoginNexusExtension {
constructor() {
this.clientId = '';
this.redirectUri = '';
this.apiUri = '';
this.authenticatedUsers = new Set();
this.registeredUsers = new Set();
}

getInfo() {
return {
id: 'loginNexus',
name: 'LoginNexus',
color1: '#ADD8E6',
color2: '#87CEEB',
color3: '#B0E0E6',
blocks: [
{
blockType: Scratch.BlockType.LABEL,
text: 'Settings'
},
{
opcode: 'setClientId',
blockType: Scratch.BlockType.COMMAND,
text: 'set client ID to [CLIENT_ID]',
arguments: {
CLIENT_ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'your-client-id'
}
}
},
{
opcode: 'setRedirectUri',
blockType: Scratch.BlockType.COMMAND,
text: 'set redirect URI to [REDIRECT_URI]',
arguments: {
REDIRECT_URI: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'your-redirect-uri'
}
}
},
{
opcode: 'setApiUrl',
blockType: Scratch.BlockType.COMMAND,
text: 'set API URL to [API_URL]',
arguments: {
API_URL: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'YOUR-API-KEY
}
}
},
{
blockType: Scratch.BlockType.LABEL,
text: 'Authentication & Registration'
},
{
opcode: 'registerUser',
blockType: Scratch.BlockType.COMMAND,
text: 'register user [USERNAME] with password [PASSWORD] ',
arguments: {
USERNAME: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'username'
},
PASSWORD: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'password'
}
}
},
{
opcode: 'loginUser',
blockType: Scratch.BlockType.COMMAND,
text: 'login user [USERNAME] with password [PASSWORD]',
arguments: {
USERNAME: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'username'
},
PASSWORD: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'password'
}
}
},
{
opcode: 'isUserStatus',
blockType: Scratch.BlockType.BOOLEAN,
text: 'is user [USERNAME] [STATUS]?',
arguments: {
USERNAME: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'username'
},
STATUS: {
type: Scratch.ArgumentType.STRING,
menu: 'statusOptions',
defaultValue: 'authenticated'
}
}
},
{
blockType: Scratch.BlockType.LABEL,
text: 'Services'
},
{
opcode: 'useService',
blockType: Scratch.BlockType.COMMAND,
text: 'use [SERVICE] to [ACTION]',
arguments: {
SERVICE: {
type: Scratch.ArgumentType.STRING,
menu: 'services',
defaultValue: 'Google'
},
ACTION: {
type: Scratch.ArgumentType.STRING,
menu: 'actions',
defaultValue: 'Register'
}
}
},
{
blockType: Scratch.BlockType.LABEL,
text: 'Debugging'
},
{
opcode: 'debugMessage',
blockType: Scratch.BlockType.REPORTER,
text: 'last debug message'
}
],
menus: {
services: {
acceptReporters: true,
items: ['Google', 'Microsoft']
},
actions: {
acceptReporters: true,
items: ['Register', 'Authenticate']
},
statusOptions: {
acceptReporters: true,
items: ['authenticated', 'registered']
}
}
};
}

setDebugMessage(message) {
this.lastDebugMessage = message;
console.log(message);
}

setClientId(args) {
this.clientId = args.CLIENT_ID;
this.setDebugMessage('Client ID set to: ' + this.clientId);
}

setRedirectUri(args) {
this.redirectUri = args.REDIRECT_URI;
this.setDebugMessage('Redirect URI set to: ' + this.redirectUri);
}

setApiUri(args) {
this.apiUri = args.API_URI;
this.setDebugMessage('API URI set to: ' + this.redirectUri);
}

async registerUser(args) {
const username = args.USERNAME;
const password = args.PASSWORD;

if (!username || !password) {
this.setDebugMessage('Invalid arguments provided');
return;
}

try {
const response = await Scratch.fetch(this.apiUrl , {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, password })
});

const data = await response.json();
if (response.ok) {
this.registeredUsers.add(username);
this.setDebugMessage('Registration successful: ' + JSON.stringify(data));
} else {
this.setDebugMessage('Registration failed: ' + JSON.stringify(data));
}
} catch (error) {
this.setDebugMessage('Error: ' + error.message);
}
}



async loginUser(args) {
const username = args.USERNAME;
const password = args.PASSWORD;

try {
const response = await Scratch.fetch(this.apiUrl);
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
const users = await response.json();

const user = users.find(u => u.username === username && u.password === password);
if (user) {
this.authenticatedUsers.add(username);
this.setDebugMessage(`Login successful for user: ${username}`);
} else {
this.setDebugMessage(`Login failed for user: ${username}`);
}
} catch (error) {
this.setDebugMessage(`Error: ${error.message}`);
}
}



isUserStatus(args) {
const username = args.USERNAME;
const status = args.STATUS;

if (!username || !status) {
this.setDebugMessage('Invalid arguments provided');
return false;
}

if (status === 'authenticated') {
return this.authenticatedUsers.has(username);
} else if (status === 'registered') {
return this.registeredUsers.has(username);
}

return false;
}


useService(args) {
const service = args.SERVICE;
const action = args.ACTION;

if (service === 'Google') {
if (action === 'Register' || action === 'Authenticate') {
this.setDebugMessage(`${action} with Google...`);
Scratch.openWindow(`https://accounts.google.com/o/oauth2/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&response_type=token&scope=email`, '_blank');
}
} else if (service === 'Microsoft') {
if (action === 'Register' || action === 'Authenticate') {
this.setDebugMessage(`${action} with Microsoft...`);
Scratch.openWindow(`https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=${this.clientId}&response_type=token&redirect_uri=${this.redirectUri}&scope=openid email profile`, '_blank');
}
}
} else {
this.setDebugMessage('Unknown service or action.');
}
}

debugMessage() {
return this.lastDebugMessage;
}
}

Scratch.extensions.register(new LoginNexusExtension());
})(Scratch);
1 change: 1 addition & 0 deletions extensions/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"bitwise",
"Skyhigh173/bigint",
"utilities",
"Thebloxers998/ServerAuth",
"sound",
"Lily/Video",
"iframe",
Expand Down
Loading
Loading