Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

error "Unauthorized request." when change to new private key #91

Closed
AddzMDev opened this issue Jan 19, 2018 · 5 comments
Closed

error "Unauthorized request." when change to new private key #91

AddzMDev opened this issue Jan 19, 2018 · 5 comments

Comments

@AddzMDev
Copy link

Just don't know what happen I've use firego for firebase realtime database and everything work fine in development but on production, I've generate new service key and replace that key with the same file that I've use in development. Then to authenticate there are no problem but I've got "error" : "Unauthorized request." when try to read data from realtime databsae

any idea ?

@AddzMDev
Copy link
Author

There was my mistake I've solved this error.

@dkoshkin
Copy link

@AddzMDev what was the issue Im running into the same issue?

@AddzMDev
Copy link
Author

AddzMDev commented Feb 21, 2018

In my case I just put wrong configuration.
For production and development environment I've use different database then to switch to the production environment I need to switch both the URL of database and service key.

@zabawaba99
Copy link
Owner

@dkoshkin, when you get a chance, can you post back with whether or not @AddzMDev configuration suggestion helped?

@AddzMDev
Copy link
Author

There are nothing special. To explain that with my code here

func firebaseAuth(keyPath, fbDbURL string) (fb *firego.Firebase, err error) {
  d, err := ioutil.ReadFile(keyPath)
  if err != nil {
    log.Println("Error : ", err.Error())
    os.Exit(0)
  }

  conf, err := google.JWTConfigFromJSON(d, "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/firebase.database")
  if err != nil {
    log.Println("Error : ", err.Error())
    os.Exit(0)
  }

  fb = firego.New(fbDbURL, conf.Client(oauth2.NoContext))
  firego.TimeoutDuration = time.Hour * 2
  
  if fb == nil {
    err = errors.New("fails to initialize firebase")
    log.Println("Error : ", err.Error())
  }
  return
}

func main() {  
  keyPath := "/path/to/your/production/key" // make sure this path is point to your production key path
  url := "https://your_product_project.firebaseio.com/" // make sure this url is your production database 

  if auth, e := firebaseAuth(keyPath, url); e != nil {
    os.Exit(0)
  } 
}

My former mistake was I had change kyePath variable in main function to production key but url variable still point to development database then Unauthorized request. error occur

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants