diff --git a/src/auth.js b/src/auth.js index c0bb902..a8db9e6 100644 --- a/src/auth.js +++ b/src/auth.js @@ -5,8 +5,9 @@ import { TwitterAuthProvider, GoogleAuthProvider, signInWithPopup, + signInWithCredential, signOut -} from 'firebase/auth'; +} from 'firebase/auth/web-extension'; import { log } from './utils'; export const authh = { @@ -14,6 +15,77 @@ export const authh = { signOut(); }, login(providerName) { + const ru = chrome.identity.getRedirectURL(''); + console.log(111, ru); + chrome.identity.launchWebAuthFlow( + { + interactive: true, + url: `https://github.com/login/oauth/authorize?client_id=5d26b6d331c0e1a66656&redirect_uri=${ru}&scope=user:email&response_type=token` + }, + function (responseUrl) { + const tokenMatch = responseUrl.match(/code=(.*)/); + console.log({ responseUrl }, tokenMatch[1]); + const token = tokenMatch ? tokenMatch[1] : null; + if (!token) { + console.error('No token found'); + return; + } + const credential = GithubAuthProvider.credential(''); + signInWithCredential(auth, credential) + .then(result => { + console.log('Success!!!'); + console.log(result); + }) + .catch(error => { + // You can handle errors here + console.log(88, error); + }); + } + ); + return; + + chrome.identity.getAuthToken({ interactive: true }, function (token) { + //Token: This requests an OAuth token from the Chrome Identity API. + if (chrome.runtime.lastError) { + console.error(chrome.runtime.lastError); + } else if (token) { + console.error(222, token); + // Follows: https://firebase.google.com/docs/auth/web/google-signin + // Authorize Firebase with the OAuth Access Token. + // console.log("TOKEN:") + // console.log(token) + // Builds Firebase credential with the Google ID token. + const credential = GoogleAuthProvider.credential(null, token); + signInWithCredential(auth, credential) + .then(result => { + console.log('Success!!!'); + console.log(result); + }) + .catch(error => { + // You can handle errors here + console.log(error); + }); + } else { + console.error('The OAuth token was null'); + } + }); + + // chrome.identity.getAuthToken({}, token => { + // console.log(7777, token); + // let credential = GoogleAuthProvider.credential(null, token); + // console.log(277, credential); + + // signInWithCredential(credential) + // .then(userCredential => { + // console.log(999, userCredential); + // }) + // .catch(error => { + // console.error(error); + // }); + // }); + + return; + var provider; if (providerName === 'facebook') { provider = new FacebookAuthProvider(); diff --git a/src/components/CodeEditor.jsx b/src/components/CodeEditor.jsx index cebf3b6..f6d3a93 100644 --- a/src/components/CodeEditor.jsx +++ b/src/components/CodeEditor.jsx @@ -234,13 +234,13 @@ export default class CodeEditor extends Component { async loadDeps() { if (this.props.type === 'monaco') { if (!monacoDepsDeferred) { - monacoDepsDeferred = deferred(); - loadCss({ url: 'lib/monaco/monaco.css', id: 'monaco-css' }); - import( - /* webpackChunkName: "monaco" */ '/lib/monaco/monaco.bundle.js' - ).then(() => { - monacoDepsDeferred.resolve(); - }); + // monacoDepsDeferred = deferred(); + // loadCss({ url: 'lib/monaco/monaco.css', id: 'monaco-css' }); + // import( + // /* webpackChunkName: "monaco" */ '/lib/monaco/monaco.bundle.js' + // ).then(() => { + // monacoDepsDeferred.resolve(); + // }); } return monacoDepsDeferred.promise; } diff --git a/src/firebaseInit.js b/src/firebaseInit.js index 83af069..c86c325 100644 --- a/src/firebaseInit.js +++ b/src/firebaseInit.js @@ -11,7 +11,16 @@ const config = { messagingSenderId: '560473480645' }; -const app = initializeApp(config); +const configStaging = { + apiKey: 'AIzaSyCU3X3p0MJHF7PUIGUJV2ipfuFx3-d9Y1I', + authDomain: 'web-maker-staging.firebaseapp.com', + projectId: 'web-maker-staging', + storageBucket: 'web-maker-staging.appspot.com', + messagingSenderId: '365859090303', + appId: '1:365859090303:web:1becf81ce3374e5f97b44a' +}; + +const app = initializeApp(configStaging); export { app }; export const auth = getAuth(app); diff --git a/src/index.ejs b/src/index.ejs index e3978c0..89a8a07 100644 --- a/src/index.ejs +++ b/src/index.ejs @@ -11,11 +11,8 @@ rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath %>manifest.json" /> - <% if (cli.env.isProd) { %> - - <% } else { %> - - <% } %> <% if (cli.manifest.theme_color) { %> + + <% if (cli.manifest.theme_color) { %> <% } %> diff --git a/src/manifest.json b/src/manifest.json index ad63062..c9259c5 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -4,7 +4,7 @@ "manifest_version": 3, "description": "Blazing fast & offline playground for your web experiments", "homepage_url": "https://webmaker.app", - "permissions": ["storage", "tabs"], + "permissions": ["storage", "tabs", "identity"], "optional_permissions": ["downloads"], "host_permissions": [""], "content_security_policy": { @@ -29,5 +29,14 @@ "icons": { "16": "icon-16.png", "48": "icon-48.png" + }, + "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp4s9naKH2y92qItJCcj3deRGjjqhDfgUR2WDe34IEYEB4PGtmx/9IO4PaO49gMr82DBRuwxCg/vr9SyiVlG1/j0TApJlkaHVsRZE4EME2rbL1vzIQRE8gNB+b5L6rPl4GPX/eFqIuUe/UgQPZAadLBVxdwBdOv5ou8OY0jrLx/h0wcLVvk9d8/ELpk28Hb2LArCBd+vIngHK55Db1GMEGAyNUVzFCTg/MZ7w5fKLpA94mF2X0/Bv9sCjj7vDir24Mp5Z/Y3obTHvpzddppAE6ZEQ3fmpRkOJ3MbuaKYm9hNHs4az6XLW6Sdlv2YcIcCfvsev/WEKUZeD8KIRtRyyPQIDAQAB", + + "oauth2": { + "client_id": "560473480645-f7l1mbbjhhs5vh5gqvgeqe0g3vv557l8.apps.googleusercontent.com", + "scopes": [ + "https://www.googleapis.com/auth/userinfo.email", + "https://www.googleapis.com/auth/userinfo.profile" + ] } }