forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase-authentication-get-token.template.sh
executable file
·55 lines (44 loc) · 1.83 KB
/
firebase-authentication-get-token.template.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Dependency: This script requires `jq` cli installed: https://stedolan.github.io/jq/
# Install via homebrew: `brew install jq`
# !!! This script is only template, you can use it to write own script to get your data from Firebase project !!!
# If you use Firebase email and password authentication service, this script generates an authentication token
# and copy it to your clipboard.
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Get Authorization Token
# @raycast.mode compact
# @raycast.packageName Firebase Authentication
# Optional parameters:
# @raycast.icon images/firebase.png
#
# Documentation:
# @raycast.description Get token from Firebase Authentication service
# @raycast.author João Melo
# @raycast.authorURL https://github.com/joaopcm
# you can find API_KEY on "Project settings -> General" page in Firebase
WEB_API_KEY=""
# you need to create an user with email and password on "Authentication -> Users" page in Firebase
EMAIL=""
PASSWORD=""
if ! jq --version download &> /dev/null; then
echo "download jq is required (https://stedolan.github.io/jq/).";
exit 1;
fi
if [ -z "$WEB_API_KEY" ] || [ -z "$EMAIL" ] || [ -z "$PASSWORD" ]; then
echo "Error: You must provide WEB_API_KEY, EMAIL, and PASSWORD variables"
exit 1
fi
# Generate the request body
json_data=$( jq -n -c \
--arg email "$EMAIL" \
--arg password "$PASSWORD" \
--arg returnSecureToken true '$ARGS.named' )
# Get data from Firebase Authentication service and copy the token to clipboard
curl -X POST \
"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=$WEB_API_KEY" \
--header 'Accept: */*' \
--header 'User-Agent: Raycast' \
--header 'Content-Type: application/json' \
--data-raw "$json_data" | jq -r '.idToken' | pbcopy
echo 'Authorization token copied to your clipboard!'