Skip to content

Instantly share code, notes, and snippets.

@nakanoasaservice
Created June 6, 2020 16:34
Show Gist options
  • Select an option

  • Save nakanoasaservice/241687ecb5219ae0ce633a884d8ab5bb to your computer and use it in GitHub Desktop.

Select an option

Save nakanoasaservice/241687ecb5219ae0ce633a884d8ab5bb to your computer and use it in GitHub Desktop.
Firebase Authorizationからトークンを発行する
import requests
from pprint import pprint
CONFIG = {
"apiKey": "YOUR API KEY",
"authDomain": "YOURPROJECTID.firebaseapp.com",
"databaseURL": "https://YOURPROJECTID.firebaseio.com",
"projectId": "YOUR PROJECT ID",
"storageBucket": "YOUR PROJECT ID.appspot.com",
"messagingSenderId": "YOUR MESSAGE SENDER ID",
"appId": "YOUR:APP:ID",
"measurementId": "YOUR MEASUREMENT ID"
}
EMAIL = 'test001@example.com'
PASSWORD = 'password'
def main():
api_key = CONFIG["apiKey"]
uri = f"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key={api_key}"
data = {"email": EMAIL, "password": PASSWORD, "returnSecureToken": True}
result = requests.post(url=uri, data=data)
user = result.json()
pprint(user)
print(user['idToken'])
if __name__ == '__main__':
main()
{'displayName': '',
'email': 'test001@example.com',
'expiresIn': '3600',
'idToken': 'YOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKEN',
'kind': 'identitytoolkit#VerifyPasswordResponse',
'localId': 'YOURLOCALID',
'refreshToken': 'YOURREFRESHTOKENYOURREFRESHTOKENYOURREFRESHTOKENYOURREFRESHTOKENYOURREFRESHTOKENYOURREFRESHTOKENYOURREFRESHTOKEN',
'registered': True}
YOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKENYOURIDTOKEN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment