You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
creds:=map[string]interface{}{
"email": email,
"passwd": passwd,
}
body, _:=json.Marshal(creds)
resp, err:=http.Post(fmt.Sprintf("http://localhost:8080/authenticate/%s", creds["email"]), "application/json", bytes.NewBuffer(body))
assert.Nil(t, err, "Unexepcted error when posting a new user account")
assert.NotNil(t, resp, "Unexpected nil response from server for posting a new account")
assert.Equal(t, expected, resp.StatusCode, "Was expecting a 200 ok on posting new user account")
deferresp.Body.Close()
target:=map[string]string{}
ifjson.NewDecoder(resp.Body).Decode(&target) !=nil {
t.Error("Failed to decode the authentication response containing tokenss")
}
varauthstring// authentication token as sent by the login req, _:=http.NewRequest("GET", "http://localhost:8080/authorize", nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", auth))
resp, err:= (&http.Client{}).Do(req)
Refresh user
varrefrstring// refresh token - please see if the auth token has not expired, that would be orphaned.req, _:=http.NewRequest("GET", "http://localhost:8080/authorize?refresh=true", nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", refr))
resp, err:= (&http.Client{}).Do(req)
deferresp.Body.Close()
target:=map[string]string{}
ifjson.NewDecoder(resp.Body).Decode(&target) !=nil {
t.Error("Failed to decode the authentication response containing tokenss")
}
Logout user
varauth, refrstring// token string form that used to authorizereq, _:=http.NewRequest("DELETE", "http://localhost:8080/authorize", nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", auth))
(&http.Client{}).Do(req)
req, _=http.NewRequest("DELETE", "http://localhost:8080/authorize?refresh=true", nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", refr))
(&http.Client{}).Do(req)