Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Commit 0616e50

Browse files
tharindulakMirage20
authored andcommitted
Add review fix
1 parent fc40cc3 commit 0616e50

File tree

1 file changed

+10
-6
lines changed
  • components/cli/pkg/registry/credentials

1 file changed

+10
-6
lines changed

components/cli/pkg/registry/credentials/read.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ func FromBrowser(username string, isAuthorized chan bool, done chan bool) (strin
6161
httpPortString = ":" + strconv.Itoa(codeReceiverPort)
6262
}
6363
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)
6565

6666
go func() {
6767
mux := http.NewServeMux()
6868
server := http.Server{Addr: httpPortString, Handler: mux}
69-
//var timer *time.Timer
7069
mux.HandleFunc(callBackUrlContext, func(w http.ResponseWriter, r *http.Request) {
7170
err := r.ParseForm()
7271
if err != nil {
@@ -188,11 +187,17 @@ func getUsernameAndTokenFromJwt(response string) (string, string, error) {
188187
return "", "", fmt.Errorf("failed to unmarshal the id_token: %v", err)
189188
}
190189
idToken, ok := (result["id_token"]).(string)
190+
if !ok {
191+
return "", "", fmt.Errorf("failed to retrieve the id_token: %v", err)
192+
}
191193
accessToken, ok := (result["access_token"]).(string)
192194
if !ok {
193195
return "", "", fmt.Errorf("failed to retrieve the access token: %v", err)
194196
}
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+
}
196201
claims := jwtToken.Claims.(jwt.MapClaims)
197202
sub, ok := claims["sub"].(string)
198203
if !ok {
@@ -205,9 +210,8 @@ func getUsernameAndTokenFromJwt(response string) (string, string, error) {
205210
// getTokenFromCode returns the JWT from the auth code provided
206211
func getTokenFromCode(code string, port int, conf *config.Conf) (string, error) {
207212
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))
211215
body := strings.NewReader(responseBody)
212216
// Token request
213217
req, err := http.NewRequest("POST", tokenUrl, body)

0 commit comments

Comments
 (0)