1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Go: Firebase Auth のトークンの作成

Posted at
get_token.go
// ---------------------------------------------------------------
//
//	get_token.go
//
//				  Feb/06/2021
// ---------------------------------------------------------------
package main

import (
	"fmt"
	"os"
	"io/ioutil"
	"net/http"
	"net/url"
	"encoding/json"
	"github.com/joho/godotenv"
)

// ---------------------------------------------------------------
func main() {

	fmt.Fprintf (os.Stderr,"*** 開始 ***\n")
	email := os.Args[1]
	password := os.Args[2]
	fmt.Fprintf (os.Stderr,"email = " + email + "\n")
	fmt.Fprintf (os.Stderr,"password = " + password + "\n")

	err := godotenv.Load(".env")
	if err != nil {
		panic(err)
		}

	api_key := os.Getenv("API_KEY")

	url_target := "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=" + api_key
	args := url.Values{}
	args.Add("email",email)
	args.Add("password",password)
	args.Add("returnSecureToken", "True")
	res, err := http.PostForm(url_target,args)
	if err != nil {
		fmt.Println("Request error:", err)
		return
	}
	defer res.Body.Close()

	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		fmt.Println("Request error:", err)
		return
	}

	str_json := string(body)
	var unit_aa map[string]interface{}
	json.Unmarshal ([]byte(str_json), &unit_aa )

	token := unit_aa["idToken"]
	fmt.Println(token)

	fmt.Fprintf (os.Stderr,"*** 終了 ***\n")
}

// ---------------------------------------------------------------
.env
API_KEY = "AIzaS....."

実行スクリプト

go run get_token.py ppp@example.com hello888 > token01.txt
go run get_token.py qqq@example.com hello999 > token02.txt

関連ページ
Python3: Firebase Auth のトークンの作成

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?