diff --git a/.gitignore b/.gitignore index 0a6c3fe2a..9b57dc206 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /node_modules +/web-server/node_modules +/web-server/public /*.log /dist /dist-zip diff --git a/package-lock.json b/package-lock.json index bd260bdd8..2fe01a026 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3624,6 +3624,11 @@ "ms": "^2.1.1" } }, + "dotenv": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-7.0.0.tgz", + "integrity": "sha512-M3NhsLbV1i6HuGzBUH8vXrtxOk+tWmzWKDMbAVSUp3Zsjm7ywFeuwrUXhmhQyRK1q5B5GGy7hcXPbj3bnfZg2g==" + }, "file-loader": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/file-loader/-/file-loader-3.0.1.tgz", @@ -8616,11 +8621,6 @@ "is-obj": "^1.0.0" } }, - "dotenv": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-7.0.0.tgz", - "integrity": "sha512-M3NhsLbV1i6HuGzBUH8vXrtxOk+tWmzWKDMbAVSUp3Zsjm7ywFeuwrUXhmhQyRK1q5B5GGy7hcXPbj3bnfZg2g==" - }, "dotenv-expand": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-5.1.0.tgz", diff --git a/package.json b/package.json index 095931cba..1180e3d90 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "build:Testnet": "cross-env NETWORK=Testnet npm run build", "watch:dev:Testnet": "cross-env NETWORK=Testnet npm run watch:dev", "watch:dev:tests": "cross-env NETWORK=Testnet RUNNING_IN_TESTS=true npm run watch:dev", - "build:tests": "cross-env NETWORK=Testnet RUNNING_IN_TESTS=true npm run build:dev" + "build:tests": "cross-env NETWORK=Testnet RUNNING_IN_TESTS=true npm run build:dev", + "webserver": "cp -R dist/web/root/* web-server/public/ && node web-server/index.js" }, "dependencies": { "@aeternity/aepp-components": "git+https://github.com/aeternity/aepp-components.git#develop", diff --git a/src/mixins/registration.js b/src/mixins/registration.js index e784f5fde..3a1da9cc2 100644 --- a/src/mixins/registration.js +++ b/src/mixins/registration.js @@ -41,7 +41,7 @@ export default { this.ifEdit = false; this.ifCreate = true; }, - async setupProfile() { + async setupProfile(isThridPartyAuth = false) { // try { // this.loading = true; //// HS_TODO:: @@ -52,22 +52,44 @@ export default { const HS_STUDIO_REGISTER_URL = `${SUPERHERO_HS_AUTH_BASE_URL}${SUPERHERO_HS_AUTH_CREDENTIAL_ISSUE_API}` const body = { - name: this.profile.name, - email: this.profile.email + user: { + name: this.profile.name, + email: this.profile.email + }, + isThridPartyAuth: false } + if(isThridPartyAuth){ + body["user"]["did"] = this.profile.did; + body["isThridPartyAuth"] = true; + } + + // console.log("Calling authserver register") + let res = await axios.post(HS_STUDIO_REGISTER_URL, body); if (!res) throw new Error("Could not register the user"); + // console.log("After getting response") res = res.data; + // console.log(res) + // console.log(res.message) if (res && res.status != 200) throw new Error(res.error); + + + // console.log(typeof(res.message)) + // console.log(res.message) + if(isThridPartyAuth && res && res.message){ + // console.log("Before setting 3rdPartyAuthVC"); + // only in case of 3rd party auth, verifiable credenital will come + localStorage.setItem("3rdPartyAuthVC", JSON.stringify(res.message)); + } this.$store.commit('addHSProfile', this.profile); this.ifEdit = true; this.ifCreate = false; this.ifAllDisabled = true; - return true; + return true; }, }, }; \ No newline at end of file diff --git a/src/popup/router/pages/Account.vue b/src/popup/router/pages/Account.vue index f95c6abc3..687df927c 100644 --- a/src/popup/router/pages/Account.vue +++ b/src/popup/router/pages/Account.vue @@ -80,6 +80,19 @@ export default { }, async created() { try { + + const vcStr = localStorage.getItem("3rdPartyAuthVC"); + if(vcStr){ + // console.log("vcStr is present"); + const vc = JSON.parse(vcStr); + // console.log("Able to parse vcStr") + if(vc){ + // console.log("Vc is not null"); + // console.log("Calling credentialsQRData()"); + this.credentialsQRData(vc); + } + } + // put it somewhere eles other whise it wont work... like somewhere when the app loads if (!this.hypersign.hsAuthDID) { const res = await axios.get(HS_AUTH_DID_URL); @@ -94,18 +107,23 @@ export default { } else { this.hsAuthDid = this.hypersign.hsAuthDID; } + localStorage.setItem("isMobileWallet", false) //Only for deeplinking if (this.$route.query.url && this.$route.query.url != '') { const JSONData = decodeURI(this.$route.query.url); this.receiveOrGiveCredential(JSONData); } + + + } catch (e) { if (e.message) this.$store.dispatch('modals/open', { name: 'default', msg: e.message }); } }, methods: { async scan() { + localStorage.setItem("isMobileWallet", true) const QRData = await this.$store.dispatch('modals/open', { name: 'read-qr-code', title: this.$t('pages.credential.scan'), @@ -122,7 +140,9 @@ export default { // console.log(data); switch(data.QRType){ case 'ISSUE_CRED': { - this.credentialsQRData(data.url); + this.credentialUrl = data.url; + let cred = await this.fetchCredential(); + this.credentialsQRData(cred); break; } case 'REQUEST_CRED': { @@ -141,6 +161,9 @@ export default { }, async fetchCredential() { + if(!this.credentialUrl){ + throw new Error("Credential Url is null or empty"); + } this.credentialUrl = this.credentialUrl + '&did=' + this.hypersign.did; this.loading = true; let response = await axios.get(this.credentialUrl); @@ -154,19 +177,18 @@ export default { return response.message; }, - async credentialsQRData(data) { + async credentialsQRData(cred) { try { - this.credentialUrl = data; - let cred = await this.fetchCredential(); - + if(!cred){ + throw new Error('Credential can not be null or empty'); + } // TODO: Check if this credential already exsits in wallet: otherwise reject const credInWallet = this.hypersign.credentials.find((x) => x.id == cred.id); if (credInWallet) { throw new Error('The credential already exist in your wallet'); } - // console.log(1) - + // console.log({ // hs_app_did: this.hypersign.did, // credentialSubjectDid: cred.credentialSubject.id @@ -175,12 +197,11 @@ export default { // TODO: Check if you are the owner of this credenital: otherwise reject if (this.hypersign.did != cred.credentialSubject.id) { throw new Error('The credential is not issued to you'); - } - - // console.log(2) + } this.$store.commit('addHSVerifiableCredentialTemp', cred); this.$router.push(`/credential/temp/${cred.id}`); + localStorage.removeItem("3rdPartyAuthVC"); } catch (e) { console.log(e); this.loading = false; diff --git a/src/popup/router/pages/Auth.vue b/src/popup/router/pages/Auth.vue new file mode 100644 index 000000000..a0ab30aea --- /dev/null +++ b/src/popup/router/pages/Auth.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/src/popup/router/pages/CredentialsDetailsAuthorize.vue b/src/popup/router/pages/CredentialsDetailsAuthorize.vue index 36581bb62..35bfae5eb 100644 --- a/src/popup/router/pages/CredentialsDetailsAuthorize.vue +++ b/src/popup/router/pages/CredentialsDetailsAuthorize.vue @@ -111,12 +111,22 @@ export default { if(response.status == 401 || response.status == 403) { throw new Error('Could not authorize the user') }else if(response.status == 200){ - if (response.message) - await this.$store.dispatch('modals/open', { + + const isMobileWallet = JSON.parse(localStorage.getItem("isMobileWallet")); + if (response.message){ + + if(!isMobileWallet){ + return window.close() + } + + await this.$store.dispatch('modals/open', { name: 'default', msg: 'Credential successfully verified', }); - this.reject() + this.reject() + } + + }else { throw new Error(response.error) } diff --git a/src/popup/router/pages/Index.vue b/src/popup/router/pages/Index.vue index 4b1f80237..f9ae4300e 100644 --- a/src/popup/router/pages/Index.vue +++ b/src/popup/router/pages/Index.vue @@ -27,19 +27,19 @@ v-model="profile.email" :disabled="ifAllDisabled" /> - + - - + @@ -65,7 +65,9 @@ import Input from '../components/Input-light'; import registration from '../../../mixins/registration'; import HypersignSsiSDK from 'hs-ssi-sdk'; import { HS_NODE_BASE_URL } from '../../utils/hsConstants' -import auth0 from "auth0-js"; +import webAuth from "../../utils/auth0Connection"; + + export default { mixins: [registration], components: { Logo,Input, SuperheroLogo, CheckBox, Button, Platforms }, @@ -73,33 +75,47 @@ export default { termsAgreed: false, IS_WEB: process.env.PLATFORM === 'web', IN_FRAME, - loading: false + loading: false, + isThridPartyAuth: false }), - methods: { - loginWithGoogle(){ + created(){ + const that = this; + + // CAN IMPROVE THIS WITH ROUTER PARAMETERS, REPLACING LOCAL STORAGE + if(localStorage.getItem("authToken") && localStorage.getItem("accessToken")){ + this.loading = true; + webAuth.client.userInfo(localStorage.getItem("accessToken"), function(err, user) { + if(err){ + this.loading = false; + this.$store.dispatch('modals/open', { name: 'default', msg:err }); + return; + } + const { email, name } = user; + that.profile.email = email; + that.profile.name = name; + that.isThridPartyAuth = true; + + localStorage.removeItem("authToken") + localStorage.removeItem("accessToken") + localStorage.removeItem("isRoute") - const newWebAuth = new auth0.WebAuth({ - domain: "fidato.us.auth0.com", - clientID: "hwM9GmM4nUstds9Fw5KsYZVDboJBeLTL", - responseType: "token id_token", - scope: "openid profile email", - // redirectUri: window.location.origin + "/app/admin/login", + that.createWallet(true); }) + + } + + }, + + methods: { + loginWithGoogle(){ - newWebAuth.popup.authorize( + + webAuth.authorize( { connection: "google-oauth2", - owp: true - }, - function (err, authRes) { - console.log(authRes, err) - if(!err){ - newWebAuth.client.userInfo(authRes.accessToken, function(err, user) { - console.log(err, user) - }) - } - + redirectUri: window.location.origin + "/auth/google?" }); + }, gotoRestore(){ this.$router.push('restoreWallet') @@ -112,6 +128,7 @@ export default { async createWallet() { + try{ if(this.profile.name == "") throw new Error("Name can not be blank"); if(this.profile.email == "") throw new Error("Email can not be blank"); @@ -122,6 +139,9 @@ export default { if (e.message) this.$store.dispatch('modals/open', { name: 'default', msg:e.message }); return; } + + + const hsSdk = new HypersignSsiSDK({ nodeUrl: HS_NODE_BASE_URL }); this.mnemonic = generateMnemonic(); @@ -186,16 +206,18 @@ export default { // this.$store.commit('switchLoggedIn', true); // this.$store.commit('updateAccount', keypair); // this.$store.commit('setActiveAccount', { publicKey: keypair.publicKey, index: 0 }); - console.log("Before setting profile") - if(await this.setupProfile()){ + // console.log("Before setting profile") + if(await this.setupProfile(this.isThridPartyAuth)){ console.log("After setting profile"); console.log("Calling setLogin") await this.$store.dispatch('setLogin', { keypair }); this.$store.commit('switchLoggedIn', true); - const msg = 'An email with a QR code has been sent to the address you provided.\ - Scan the QR code to receieve the credential' - this.$store.dispatch('modals/open', { name: 'default', msg }); + if(!this.isThridPartyAuth){ + const msg = 'An email with a QR code has been sent to the address you provided.\ + Scan the QR code to receieve the credential' + this.$store.dispatch('modals/open', { name: 'default', msg }); + } Object.assign(this.profile, {}); console.log("Moving to next route") @@ -215,11 +237,17 @@ export default { //////////////////////////////////////////////// } } + };