@@ -61,12 +61,11 @@ func FromBrowser(username string, isAuthorized chan bool, done chan bool) (strin
61
61
httpPortString = ":" + strconv .Itoa (codeReceiverPort )
62
62
}
63
63
redirectUrl := url .QueryEscape (fmt .Sprintf (callBackUrl , codeReceiverPort ))
64
- var hubAuthUrl = conf . Hub . Url + " /sdk/sign-in?redirectUrl=" + redirectUrl
64
+ var hubAuthUrl = fmt . Sprintf ( "%s /sdk/sign-in?redirectUrl=%s" , conf . Hub . Url , redirectUrl )
65
65
66
66
go func () {
67
67
mux := http .NewServeMux ()
68
68
server := http.Server {Addr : httpPortString , Handler : mux }
69
- //var timer *time.Timer
70
69
mux .HandleFunc (callBackUrlContext , func (w http.ResponseWriter , r * http.Request ) {
71
70
err := r .ParseForm ()
72
71
if err != nil {
@@ -188,11 +187,17 @@ func getUsernameAndTokenFromJwt(response string) (string, string, error) {
188
187
return "" , "" , fmt .Errorf ("failed to unmarshal the id_token: %v" , err )
189
188
}
190
189
idToken , ok := (result ["id_token" ]).(string )
190
+ if ! ok {
191
+ return "" , "" , fmt .Errorf ("failed to retrieve the id_token: %v" , err )
192
+ }
191
193
accessToken , ok := (result ["access_token" ]).(string )
192
194
if ! ok {
193
195
return "" , "" , fmt .Errorf ("failed to retrieve the access token: %v" , err )
194
196
}
195
- jwtToken , _ := jwt .Parse (idToken , nil )
197
+ jwtToken , err := jwt .Parse (idToken , nil )
198
+ if err != nil {
199
+ return "" , "" , fmt .Errorf ("failed to parse the id_token: %v" , err )
200
+ }
196
201
claims := jwtToken .Claims .(jwt.MapClaims )
197
202
sub , ok := claims ["sub" ].(string )
198
203
if ! ok {
@@ -205,9 +210,8 @@ func getUsernameAndTokenFromJwt(response string) (string, string, error) {
205
210
// getTokenFromCode returns the JWT from the auth code provided
206
211
func getTokenFromCode (code string , port int , conf * config.Conf ) (string , error ) {
207
212
tokenUrl := conf .Idp .Url + "/oauth2/token"
208
- responseBody := "client_id=" + conf .Idp .ClientId +
209
- "&grant_type=authorization_code&code=" + code +
210
- "&redirect_uri=" + fmt .Sprintf (callBackUrl , port )
213
+ responseBody := fmt .Sprintf ("client_id=%s&grant_type=authorization_code&code=%s&redirect_uri=%s" ,
214
+ conf .Idp .ClientId , code , fmt .Sprintf (callBackUrl , port ))
211
215
body := strings .NewReader (responseBody )
212
216
// Token request
213
217
req , err := http .NewRequest ("POST" , tokenUrl , body )
0 commit comments