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

OAUTH #1752

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft

OAUTH #1752

Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# ESLint is a tool for identifying and reporting on patterns
# found in ECMAScript/JavaScript code.
# More details at https://github.com/eslint/eslint
# and https://eslint.org

name: ESLint

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '21 18 * * 5'

jobs:
eslint:
name: Run eslint scanning
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install ESLint
run: |
npm install [email protected]
npm install @microsoft/[email protected]

- name: Run ESLint
env:
SARIF_ESLINT_IGNORE_SUPPRESSED: "true"
run: npx eslint .
--config .eslintrc.js
--ext .js,.jsx,.ts,.tsx
--format @microsoft/eslint-formatter-sarif
--output-file eslint-results.sarif
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: eslint-results.sarif
wait-for-processing: true
2 changes: 1 addition & 1 deletion CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extensions.turbowarp.org
extensions.turbowarp.org
238 changes: 238 additions & 0 deletions extensions/OAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
// Name: OAuth
// ID: oauthExtension
// Description: Uses OAuth for authentication and registration
// By: Thebloxers998 <https://scratch.mit.edu/users/Thebloxers998/>
// Original: Thebloxers998
// License: MPL-2.0
(function (Scratch) {
'use strict';
if (!Scratch.extensions.unsandboxed) {
throw new Error('This extension must run unsandboxed');
}
let clientId = '';
let clientSecret = '';
let redirectUri = '';
let authUrl = '';

class OAuthExtension {
getInfo() {
return {
id: 'oauthExtension',
name: 'OAuth',
color1: '#8B0000', // Dark red color
color2: '#8B0000', // Dark red color
color3: '#8B0000', // Dark red color
blocks: [
{
opcode: 'setClientId',
blockType: Scratch.BlockType.COMMAND,
text: 'Set Client ID [ID]',
arguments: {
ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Your Client ID'
}
}
},
{
opcode: 'setClientSecret',
blockType: Scratch.BlockType.COMMAND,
text: 'Set Client Secret [SECRET]',
arguments: {
SECRET: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Your Client Secret'
}
}
},
{
opcode: 'setRedirectUri',
blockType: Scratch.BlockType.COMMAND,
text: 'Set Redirect URI [URI]',
arguments: {
URI: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Your Redirect URI'
}
}
},
{
opcode: 'setAuthUrl',
blockType: Scratch.BlockType.COMMAND,
text: 'Set Auth URL [URL]',
arguments: {
URL: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Your Auth URL'
}
}
},
{
opcode: 'registerAccount',
blockType: Scratch.BlockType.COMMAND,
text: 'Register account with OAuth',
arguments: {}
},
{
opcode: 'authenticate',
blockType: Scratch.BlockType.COMMAND,
text: 'Authenticate with [SERVICE]',
arguments: {
SERVICE: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Service Name'
}
}
},
{
opcode: 'changeClientId',
blockType: Scratch.BlockType.COMMAND,
text: 'Change Client ID to [ID]',
arguments: {
ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'New Client ID'
}
}
},
{
opcode: 'changeClientSecret',
blockType: Scratch.BlockType.COMMAND,
text: 'Change Client Secret to [SECRET]',
arguments: {
SECRET: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'New Client Secret'
}
}
},
{
opcode: 'changeRedirectUri',
blockType: Scratch.BlockType.COMMAND,
text: 'Change Redirect URI to [URI]',
arguments: {
URI: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'New Redirect URI'
}
}
},
{
opcode: 'changeAuthUrl',
blockType: Scratch.BlockType.COMMAND,
text: 'Change Auth URL to [URL]',
arguments: {
URL: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'New Auth URL'
}
}
},
{
opcode: 'giveFeedback',
blockType: Scratch.BlockType.BUTTON,
text: 'Give Feedback'
}
],
menus: {}
};
}

setClientId(args) {
clientId = args.ID;
console.log(`Client ID set to: ${clientId}`);
}

setClientSecret(args) {
clientSecret = args.SECRET;
console.log(`Client Secret set to: ${clientSecret}`);
}

setRedirectUri(args) {
redirectUri = args.URI;
console.log(`Redirect URI set to: ${redirectUri}`);
}

setAuthUrl(args) {
authUrl = args.URL;
console.log(`Auth URL set to: ${authUrl}`);
}

registerAccount() {
const fullAuthUrl = `${authUrl}?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code`;

Scratch.openWindow(fullAuthUrl, '_blank');

window.addEventListener('message', (event) => {
if (event.origin !== redirectUri) return;
const authorizationCode = event.data;
console.log(`Received authorization code: ${authorizationCode}`);

// Exchange the authorization code for an access token
Scratch.fetch('https://example.com/oauth/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
client_id: clientId,
client_secret: clientSecret,
code: authorizationCode,
redirect_uri: redirectUri,
grant_type: 'authorization_code'
})
})
.then(response => response.json())
.then(data => {
const accessToken = data.access_token;
console.log(`Received access token: ${accessToken}`);
// Use the access token to register the user
})
.catch(error => {
console.error('Error exchanging authorization code:', error);
});
});
}

authenticate(args) {
const service = args.SERVICE;
const fullAuthUrl = `${authUrl}?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=token`;

Scratch.openWindow(fullAuthUrl, '_blank');

window.addEventListener('message', (event) => {
if (event.origin !== redirectUri) return;
const token = event.data;
console.log(`Authenticated with ${service}: ${token}`);
// Store the token securely
});
}

changeClientId(args) {
clientId = args.ID;
console.log(`Client ID changed to: ${clientId}`);
}

changeClientSecret(args) {
clientSecret = args.SECRET;
console.log(`Client Secret changed to: ${clientSecret}`);
}

changeRedirectUri(args) {
redirectUri = args.URI;
console.log(`Redirect URI changed to: ${redirectUri}`);
}

changeAuthUrl(args) {
authUrl = args.URL;
console.log(`Auth URL changed to: ${authUrl}`);
}

giveFeedback() {
Scratch.openWindow('https://scratch.mit.edu/users/Thebloxers998/');
}
}

Scratch.extensions.register(new OAuthExtension());
})(Scratch);

1 change: 1 addition & 0 deletions extensions/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"Lily/MoreEvents",
"Lily/ListTools",
"veggiecan/mobilekeyboard",
"Thebloxers998/OAuth",
"NexusKitten/moremotion",
"CubesterYT/WindowControls",
"veggiecan/browserfullscreen",
Expand Down
Loading