createAccessAuthenticatedStream will try load a token from storage and make a connection with the token set on the request. If it still get redirect, this probably means the token in storage is invalid (expired/revoked). If that happens it deletes the token and runs the connection again, so the user
(options *StartOptions, log *zerolog.Logger)
| 154 | // happens it deletes the token and runs the connection again, so the user can |
| 155 | // login again and generate a new one. |
| 156 | func createAccessAuthenticatedStream(options *StartOptions, log *zerolog.Logger) (*websocket.Conn, error) { |
| 157 | wsConn, resp, err := createAccessWebSocketStream(options, log) |
| 158 | defer closeRespBody(resp) |
| 159 | if err == nil { |
| 160 | return wsConn, nil |
| 161 | } |
| 162 | |
| 163 | if !IsAccessResponse(resp) { |
| 164 | return nil, err |
| 165 | } |
| 166 | |
| 167 | // Access Token is invalid for some reason. Go through regen flow |
| 168 | if err := token.RemoveTokenIfExists(options.AppInfo); err != nil { |
| 169 | return nil, err |
| 170 | } |
| 171 | wsConn, resp, err = createAccessWebSocketStream(options, log) |
| 172 | defer closeRespBody(resp) |
| 173 | if err != nil { |
| 174 | return nil, err |
| 175 | } |
| 176 | |
| 177 | return wsConn, nil |
| 178 | } |
| 179 | |
| 180 | // createAccessWebSocketStream builds an Access request and makes a connection |
| 181 | func createAccessWebSocketStream(options *StartOptions, log *zerolog.Logger) (*websocket.Conn, *http.Response, error) { |
no test coverage detected