-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_jwt.sh
executable file
·72 lines (58 loc) · 1.83 KB
/
get_jwt.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Copyright (C) CampusIoT, - All Rights Reserved
# Written by CampusIoT Dev Team, 2016-2018
# Parameters
if [[ $# -ne 2 ]] ; then
echo "Usage: $0 USERNAME PASSWORD"
exit 1
fi
USERNAME=$1
PASSWORD=$2
# Installation
if ! [ -x "$(command -v jq)" ]; then
>&2 echo 'jq is not installed. Installing jq ...'
sudo apt-get install -y jq
fi
if ! [ -x "$(command -v curl)" ]; then
>&2 echo 'curl is not installed. Installing curl ...'
sudo apt-get install -y curl
fi
# Content-Type
ACCEPT_JSON="Accept: application/json"
ACCEPT_CSV="Accept: text/csv"
CONTENT_JSON="Content-Type: application/json"
CONTENT_CSV="Content-Type: text/csv"
# LOCAL
#PORT=8888
#URL=http://localhost:$PORT
# PROD
PORT=443
URL=https://lns.campusiot.imag.fr:$PORT
# Doc
URL_SWAGGER=${URL}/swagger/api.swagger.json
# Operations
# CURL="curl --verbose"
#CURL="curl -k --verbose --insecure"
CURL="curl -k --insecure"
GET="${CURL} -X GET --header \""$ACCEPT_JSON"\""
POST="${CURL} -X POST --header \""$ACCEPT_JSON"\""
PUT="${CURL} -X PUT --header \""$ACCEPT_JSON"\""
DELETE="${CURL} -X DELETE --header \""$ACCEPT_JSON"\""
OPTIONS="${CURL} -X OPTIONS --header \""$ACCEPT_JSON"\""
HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
# ===================================
# Get OpenAPI2.0 specification of the API
# -----------------------------------
#${GET} ${URL_SWAGGER} > api.swagger.json
# ===================================
# Authenfication operations
# -----------------------------------
AUTH_JSON="{ \"username\": \"${USERNAME}\", \"password\": \"${PASSWORD}\" }"
# Get the Bearer token for the user
rm $USERNAME.token.json
${POST} --header "$CONTENT_JSON" -d "$AUTH_JSON" ${URL}/api/internal/login > $USERNAME.token.json
TOKEN=$(jq -r '.jwt' $USERNAME.token.json)
AUTH="Grpc-Metadata-Authorization: Bearer $TOKEN"
echo "$TOKEN"
#sudo npm install -g jwt-cli
#jwt $TOKEN