-
Notifications
You must be signed in to change notification settings - Fork 0
/
brokerRedirectPrint.sh
177 lines (132 loc) · 4.71 KB
/
brokerRedirectPrint.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
#
# Requirements
# Install and setup Java We assume $JAVA_HOME is set
# Install openssl either through your linux package manager or macOS package manager (we like brew)
# Update to keystore folders for debug and release
set -o errtrace
set -o pipefail
package_name="com.your.app"
java_bin=$JAVA_HOME/jre/bin
keytool=$java_bin/keytool
debug_key_store=$HOME/.android/debug.keystore
release_alias="androiddebugkey"
release_key_store=$HOME/.android/release.keystore
release_password="android"
android_key_store=
usage() {
echo ""
echo " This tool generates a ReplyURL you'll need to enter in to your Azure Portal"
echo " to allow for your app to use the Microsoft Accounts broker app. This will"
echo " allow your app to particiapte in SSO and do Certificate based authentication"
echo " among other good things./n"
echo ""
echo "Usage:";
echo " -d | --debug genrates a replyURL using your debug keystore in Android Studio"
echo " -r | --release generates a replyURL using your production keystore in Android Studio"
echo " -c | --package the package name of your application"
echo " -p | --password your keystore password (default for debug keychain is android)"
echo " -a | --alias your keystore alias (default for debug keychain is androiddebugkey)"
echo ""
}
if [ $# -gt 0 ]; then
while [ "$1" != "" ]; do
case $1 in
-d | --debug) debug=1
;;
-r | --release ) release=1
;;
-c | --package ) shift
package_name=$1
;;
-p | --password ) shift
release_password=$1
;;
-a | --alias ) shift
release_alias=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
else
usage
fi
#---------------------------------
# Simple func() to encode a URL. Wrote it so we don't have an external dependency
#
rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) echo -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}" # You can either set a return variable (FASTER)
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
}
#---------------------------------
#---------------------------------
# Simple Func() to generate the hash from the certificate provided by the android keystore.
makeTag() {
tag=`$keytool -storepass $release_password -exportcert -alias $release_alias -keystore $android_key_store | openssl sha1 -binary | openssl base64`
}
#---------------------------------
#---------------------------------
makeReplyURL() {
printf "msauth://%s/%s\n" $package_name_encoded $tag
}
#---------------------------------
# Simple Func() to do release
makerelease() {
if [ -f "$release_key_store" ]; then
android_key_store=$release_key_store
echo "We are using the following values"
printf "Package Name: %s\n" $package_name
printf "Keystore alias: %s\n" $release_alias
printf "Keystore password: %s\n" $release_password
printf "Keystore: %s\n" $android_key_store
makeTag
echo "Release Redirect URI is:"
makeReplyURL
else
printf "ERROR: The Release Android Key Store location %s was not found. Have you set up Android Studio for Google Play?\n" $android_key_store
fi
}
#---------------------------------
# Simple Func() to do debug
makedebug() {
if [ -f "$debug_key_store" ]; then
android_key_store=$debug_key_store
echo "We are using the following values"
printf "Package Name: %s\n" $package_name
printf "Keystore alias: %s\n" $release_alias
printf "Keystore password: %s\n" $release_password
printf "Keystore: %s\n" $android_key_store
makeTag
echo "Debug Redirect URI is:"
makeReplyURL
else
printf "ERROR: The Debug Android Key Store location %s was not found. Try deploying your app in debug mode first to generate keys.\n" $android_key_store
fi
}
#---------------------------------
# main
# Encoding the package name
package_name_encoded=`rawurlencode "$package_name"`
if [ "$debug" = "1" ]; then
makedebug
fi
if [ "$release" = "1" ]; then
makerelease
fi