Skip to content

Commit

Permalink
Merge pull request #379 from CirclesUBI/feature/app-253-implement-aut…
Browse files Browse the repository at this point in the history
…h-flow-without-2fa-new-web3auth

Feature/app 253 implement auth flow without 2fa new web3auth
  • Loading branch information
codeho authored Jul 30, 2023
2 parents f89f7ab + c681aff commit f995fb6
Show file tree
Hide file tree
Showing 10 changed files with 575 additions and 197 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
9 changes: 6 additions & 3 deletions shell/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@o-platform/shell",
"version": "1.0.0",
"version": "1.0.2",
"author": "Daniel Janz, Thorsten Schau & Samuel Andert (Basic Income Lab GmbH)",
"license": "AGPL-3.0-or-later",
"description": "CirclesUBI Indonesia web app",
"scripts": {
"clean:all": "npx shx rm -rf public/bundle.* && npx shx rm -rf node_modules",
"clean": "npx shx rm -rf public/bundle.*",
"local": "ENVIRONMENT='local' USE_MOCKS='true' webpack serve --hot --config webpack.config.js --mode=development",
"docker": "DEPLOY_ENVIRONMENT='docker' USE_MOCKS='true' DEFAULT_APP_LANGUAGE=id I18N_FILE_URL_TEMPLATE='https://raw.githubusercontent.com/CirclesUBI/o-platform-i18n/dev/{locale}.json' ENVIRONMENT='docker' HERE_API_KEY='TAyr4mDOyPVD3DUwlUhLgV-hQxIsXGl3wnlyTkTPWsA' webpack serve --hot --host 0.0.0.0 --port 8080 --config webpack.config.js --mode=development",
"docker": "DEPLOY_ENVIRONMENT='docker' DEFAULT_APP_LANGUAGE=id I18N_FILE_URL_TEMPLATE='https://raw.githubusercontent.com/CirclesUBI/o-platform-i18n/dev/{locale}.json' ENVIRONMENT='docker' HERE_API_KEY='TAyr4mDOyPVD3DUwlUhLgV-hQxIsXGl3wnlyTkTPWsA' webpack serve --hot --host 0.0.0.0 --port 8080 --config webpack.config.js --mode=development",
"override": "DEFAULT_APP_LANGUAGE=id I18N_FILE_URL_TEMPLATE='https://raw.githubusercontent.com/CirclesUBI/o-platform-i18n/dev/{locale}.json' ENVIRONMENT='override' I18N_FILE_URL_TEMPLATE='https://raw.githubusercontent.com/CirclesUBI/o-platform-i18n/dev/{locale}.json' webpack serve --hot --host localhost --https --port 8080 --config webpack.config.js --mode=development",
"build": "cross-env NODE_ENV=production webpack",
"validate": "svelte-check"
Expand All @@ -29,7 +29,10 @@
"@toruslabs/openlogin": "^3.2.1",
"@toruslabs/openlogin-ed25519": "^4.2.0",
"@toruslabs/openlogin-utils": "^4.5.1",
"@web3auth/ethereum-provider": "^5.1.1",
"@web3auth/base": "^6.1.6",
"@web3auth/ethereum-provider": "^6.1.5",
"@web3auth/no-modal": "6.1.6",
"@web3auth/openlogin-adapter": "^6.1.6",
"@xstate/svelte": "^1.0.0",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
Expand Down
79 changes: 34 additions & 45 deletions shell/src/dapps/o-onboarding/processes/loginWithTorus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import HtmlViewer from "../../../../../packages/o-editors/src/HtmlViewer.svelte"
import { PlatformEvent } from "@o-platform/o-events/dist/platformEvent";
import { show } from "@o-platform/o-process/dist/actions/show";
import ErrorView from "../../../shared/atoms/Error.svelte";
import { getOpenLogin } from "../../../shared/openLogin";
import { Web3Auth } from "../../../shared/web3AuthNoModal";
import { FindInvitationCreatorDocument, Profile, QueryFindInvitationCreatorArgs } from "../../../shared/api/data/types";
import { ApiClient } from "../../../shared/apiConnection";
import { AvataarGenerator } from "../../../shared/avataarGenerator";
Expand Down Expand Up @@ -53,6 +53,13 @@ let loginOptions = [
class: "btn btn-outline",
icon: "apple",
},
{
key: "facebook",
label: window.o.i18n("dapps.o-onboarding.processes.loginWithTorus.loginOptions.facebook.label"),
target: "#facebook",
class: "btn btn-outline",
icon: "facebook",
},
];

const processDefinition = (processId: string) =>
Expand Down Expand Up @@ -119,12 +126,12 @@ const processDefinition = (processId: string) =>
context.data.accountAddress = accAddress;
} else {
// Init open login
await getOpenLogin();
new Web3Auth();
}
},
onDone: [
{
cond: (context) => context.data.useMockProfileIndex !== undefined,
cond: (context) => Environment.useMockLogin === true,
target: "useMockProfile",
},
{
Expand Down Expand Up @@ -188,28 +195,11 @@ const processDefinition = (processId: string) =>
],
invoke: {
src: async (context) => {
const mockProfile = Environment.getTestProfile(context.data.useMockProfileIndex);
console.log("MOCKPF", mockProfile);
const openLogin = <any>{
async login(params: any): Promise<{ privKey: string }> {
return {
privKey: mockProfile.privateKey,
};
},
async getUserInfo(): Promise<any> {
delete mockProfile.privateKey;
return mockProfile;
},
};
const privateKey = await openLogin.login({
loginProvider: "google",
extraLoginOptions: {
prompt: "select_account",
display: "touch",
},
});

const userInfo = await openLogin.getUserInfo();
const webauth = new Web3Auth();
await webauth.init();
await webauth.login("mock", context.data.useMockProfileIndex);
const privateKey = await webauth.getPrivateKey();
const userInfo = await webauth.getUserInfo(context.data.useMockProfileIndex);
return {
privateKey: privateKey.privKey,
userInfo: userInfo,
Expand Down Expand Up @@ -248,16 +238,11 @@ const processDefinition = (processId: string) =>
],
invoke: {
src: async (context) => {
const openLogin = await getOpenLogin();
const privateKey = await openLogin.login({
loginProvider: "google",
extraLoginOptions: {
prompt: "select_account",
display: "touch",
},
});

const userInfo = await openLogin.getUserInfo();
const webauth = new Web3Auth();
await webauth.init();
await webauth.login("google");
const privateKey = await webauth.getPrivateKey();
const userInfo = await webauth.getUserInfo();
return {
privateKey: privateKey.privKey,
userInfo: userInfo,
Expand Down Expand Up @@ -296,13 +281,15 @@ const processDefinition = (processId: string) =>
],
invoke: {
src: async (context) => {
const openLogin = await getOpenLogin();
const privateKey = await openLogin.login({
loginProvider: "apple",
});
const webauth = new Web3Auth();
await webauth.init();
await webauth.login("apple");
const privateKey = await webauth.getPrivateKey();
const userInfo = await webauth.getUserInfo();

return {
privateKey: privateKey.privKey,
userInfo: await openLogin.getUserInfo(),
userInfo: userInfo,
};
},

Expand All @@ -328,13 +315,15 @@ const processDefinition = (processId: string) =>
id: "facebook",
invoke: {
src: async (context) => {
const openLogin = await getOpenLogin();
const privateKey = await openLogin.login({
loginProvider: "facebook",
});
const webauth = new Web3Auth();
await webauth.init();
await webauth.login("facebook");
const privateKey = await webauth.getPrivateKey();
const userInfo = await webauth.getUserInfo();

return {
privateKey: privateKey.privKey,
userInfo: await openLogin.getUserInfo(),
userInfo: userInfo,
};
},
onDone: {
Expand Down
10 changes: 6 additions & 4 deletions shell/src/dapps/o-passport/processes/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { PlatformEvent } from "@o-platform/o-events/dist/platformEvent";
import { show } from "@o-platform/o-process/dist/actions/show";
import { push } from "svelte-spa-router";
import { LogoutDocument } from "../../../shared/api/data/types";
import { getOpenLogin } from "../../../shared/openLogin";

import ErrorView from "../../../shared/atoms/Error.svelte";
import { Web3Auth } from "../../../shared/web3AuthNoModal";

export type LogoutContextData = {
successAction: (data: LogoutContextData) => void;
Expand Down Expand Up @@ -42,8 +43,7 @@ const processDefinition = (processId: string) =>
id: "logout",
invoke: {
src: async (context) => {
const openLogin = await getOpenLogin();

const webauth = new Web3Auth();
sessionStorage.removeItem("circlesKey");
sessionStorage.removeItem("SurveySessionId");
sessionStorage.removeItem("inviteUrl");
Expand Down Expand Up @@ -83,7 +83,9 @@ const processDefinition = (processId: string) =>
const result = await apiClient.mutate({
mutation: LogoutDocument,
});
await openLogin.logout();

await webauth.init();
await webauth.logout();

return result.data.logout.success;
},
Expand Down
43 changes: 0 additions & 43 deletions shell/src/shared/openLogin.ts

This file was deleted.

3 changes: 2 additions & 1 deletion shell/src/shared/processes/actions/setWindowLastError.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const setWindowLastError = (context, event) => {
window.o.lastError = event.data;
};
console.log("EVENT", event);
};
12 changes: 1 addition & 11 deletions shell/src/shared/stores/pagedEventQuery.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
EventPayload,
EventType,
PaginationArgs,
Profile,
ProfileEvent,
ProfileEventFilter,
QueryEventsArgs,
SortOrder,
StreamDocument,
} from "../api/data/types";
import { EventPayload, EventType, PaginationArgs, Profile, ProfileEvent, ProfileEventFilter, QueryEventsArgs, SortOrder, StreamDocument } from "../api/data/types";
import { writable } from "svelte/store";
import { me } from "./me";
import { Environment } from "../environment";
Expand Down
Loading

0 comments on commit f995fb6

Please sign in to comment.