Giter Club home page Giter Club logo

Comments (7)

mironal avatar mironal commented on July 24, 2024

Thanks your question!

I will check and feedback soon 😄

from electron-oauth-helper.

mironal avatar mironal commented on July 24, 2024

hmm... When I tried electron-oauth-helper at electron-vue, no error occurred.

However, executing perform before opening window caused an error.
But, that was different from the error you wrote.

May I ask you to try the following?

  1. Please check if the version of electron-oauth-helper in package.json -> dependencies is 1.0.2.
  2. Please check if the version of nodejs you are using is 8.9.2.
  3. remove dist dir and run npm run dev

Here is the code I tried.

function createWindow () {
  /**
   * Initial window options
   */
  mainWindow = new BrowserWindow({
    height: 563,
    useContentSize: true,
    width: 1000
  })

  mainWindow.loadURL(winURL)

  mainWindow.on('closed', () => {
    mainWindow = null
  })
  
  // Be careful! 
  // An error will occur if window is not opened
  setTimeout(() => {
    try {
      const p = new OAuth2Provider({
        // this is example
        authorize_url: 'https://www.google.co.jp',
        redirect_url: 'https://www.google.co.jp',
        client_id: 'aa',
        client_secret: 'aa'
      })
      p.perform({})
        .then(() => {
          console.log('aa')
        })
        .catch(console.error)
    } catch (error) {
      console.error(error)
    }
  }, 3000)
}

image

from electron-oauth-helper.

MatiasVME avatar MatiasVME commented on July 24, 2024

Hello, thanks for the answer ... I have the 1.0.2 version of electron-oauth-helper and node 8.9.2 ... I'm trying with your code and works 😃

Now I have to see if I can make the user register to firebase.

Many thanks

from electron-oauth-helper.

mironal avatar mironal commented on July 24, 2024

I will close the issue but please feel free to reopen if there is any problem.

from electron-oauth-helper.

MatiasVME avatar MatiasVME commented on July 24, 2024

Thanks, and Hello again 😅

Now i have a error with the token, that is my code:

'use strict'

import { app, BrowserWindow } from 'electron'

// const ipc = require('electron').ipcMain

/**
 * Set `__static` path to static files in production
 * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
 */
if (process.env.NODE_ENV !== 'development') {
  global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}

let mainWindow
const winURL = process.env.NODE_ENV === 'development'
  ? `http://localhost:9080`
  : `file://${__dirname}/index.html`

const { OAuth2Provider } = require('electron-oauth-helper')
const mapTypeToConfig = require('../../services/config')

const Firebase = require('firebase')
Firebase.initializeApp(mapTypeToConfig('Firebase'))

// const queryString = require('query-string')

function createWindow () {
  /**
   * Initial window options
   */
  mainWindow = new BrowserWindow({
    height: 563,
    useContentSize: true,
    width: 1000
  })

  mainWindow.loadURL(winURL)

  mainWindow.on('closed', () => {
    mainWindow = null
  })

  mainWindow.setMenu(null)

  Firebase.auth().onAuthStateChanged(function (user) {
    console.log('user 1: ', user)
  })

  setTimeout(() => {
    try {
      const provider = new OAuth2Provider(mapTypeToConfig('GoogleClientWebApp'))

      provider.perform().then(resp => {
        // const query = queryString.parse(resp)
        console.log('resp 1: ', resp['access_token'])
        // console.log('resp 2: ', resp.getAuthResponse().id_token)
        const credential = Firebase.auth.GoogleAuthProvider.credential(resp['access_token'])
        Firebase.auth().signInWithCredential(credential)
          .then(user => { console.log('user 2: ', user) })
          .catch(error => console.error('error: ', error))
      })
        .catch(error => console.error(error))
    } catch (error) {
      console.error(error)
    }
  }, 3000)
}

app.on('ready', createWindow)

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (mainWindow === null) {
    createWindow()
  }
})

The line is wrong??

const credential = Firebase.auth.GoogleAuthProvider.credential(resp['access_token'])

That is the error -->

error:  { [Error: {"error":{"errors":[{"domain":"global","reason":"invalid","message":"Unable to parse Google id_token: //SECRET//"}],"code":400,"message":"Unable to parse Google id_token: //SECRET//"}}]
    code: 'auth/internal-error',
    message: '{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Unable to parse Google id_token: //SECRET//"}],"code":400,"message":"Unable to parse Google id_token: //SECRET//"}}' }

The token it looks like this (//SECRET// is not the same :D )

yf59.GlwcxdLccCpL1EI9hLRPMekvy6xwgSEiijJhdPJyAjP4tZ7UTc6IsSbvohyyqjzlH5zBPzr8po699Y7HpfDJv66X4ktdDtGM6c95CfjvZ9tCz-IoaDxy6CDctysYTA

I can provide more info if you want.

from electron-oauth-helper.

mironal avatar mironal commented on July 24, 2024

Good morning! Japan is now at 8:00.

I got the same error when I tried connecting google and firebase auth.

And I finally found the right way. Here is example code.

// https://firebase.google.com/docs/reference/js/firebase.auth.GoogleAuthProvider#.credential
//**************************************************************↓ Be careful! first argument is null.
const credential = firebase.auth.GoogleAuthProvider.credential(null, resp.access_token)
firebase.auth().signInWithCredential(credential)
  .then(result => {
    console.log("joined google", result)
  })
  .catch(error => {
    console.error(error)
  })

And here is complete example code.

https://github.com/mironal/electron-oauth-helper/blob/master/example/src/render/index.js#L43

Enjoy! 😄

from electron-oauth-helper.

MatiasVME avatar MatiasVME commented on July 24, 2024

Good morning to 😃 ! Chile is now at 9:00

😮 Thanks is working now :D

Many thanks :)

from electron-oauth-helper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.