MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / createAccessAuthenticatedStream

Function createAccessAuthenticatedStream

carrier/websocket.go:156–178  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

154// happens it deletes the token and runs the connection again, so the user can
155// login again and generate a new one.
156func 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
181func createAccessWebSocketStream(options *StartOptions, log *zerolog.Logger) (*websocket.Conn, *http.Response, error) {

Callers 1

createWebsocketStreamFunction · 0.85

Calls 4

RemoveTokenIfExistsFunction · 0.92
closeRespBodyFunction · 0.85
IsAccessResponseFunction · 0.85

Tested by

no test coverage detected