# AuthenticationHeaderHandler

- File ID: file:17v8pus:authenticationheaderhandler-cs
- Path: NexusReader.Web.Client/Handlers/AuthenticationHeaderHandler.cs
- Role: handler
- Layer: infrastructure

## Purpose

A HTTP DelegatingHandler for the client that appends stored JWTs to trusted requests, forces browser credentials for SSR, and transparently refreshes expired tokens in a thread-safe manner.

## Key Details

Appends JWT only for trusted origins and non-auth endpoints; transparently attempts refresh on 401 using a semaphore to avoid duplicate refreshes; resolves IIdentityService in an explicit scope and will call LogoutAsync on refresh failure; clones HttpRequestMessage to safely retry requests with new token.

## Symbols

- AuthenticationHeaderHandler: A HTTP DelegatingHandler for the client that appends stored JWTs to trusted requests, forces browser credentials for SSR, and transparently refreshes expired tokens in a thread-safe manner.
- SendAsync(): Intercepts outgoing HTTP requests to add a Bearer token for trusted origins, forwards the request, and on 401 attempts a thread-safe token refresh and optionally retries the request with the new token.
- CloneHttpRequestMessageAsync(): Creates a deep clone of an HttpRequestMessage (including content stream and headers) suitable for resending.
- AuthenticationHeaderHandler: Delegating handler that secures outgoing HTTP calls by attaching and refreshing JWTs.

## Dependencies

- No resolved dependencies.

## Calls

- No resolved calls.

## Unresolved References

- dependency-target: NexusReader.Application.Abstractions.Services (INativeStorageService, IIdentityService)
- dependency-target: Microsoft.AspNetCore.Components (NavigationManager)
- dependency-target: IServiceProvider (DI resolution)
- call-target: unknown
- call-target: unknown
- call-target: unknown
- call-target: unknown
- call-target: unknown
- call-target: self
- interaction-target: protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
- interaction-target: Calls INativeStorageService.GetSecureString to obtain JWT
- interaction-target: var response = await base.SendAsync(request, cancellationToken);
- interaction-target: Delegates to base.SendAsync to perform network call
- interaction-target: identityService.RefreshTokenAsync(); if success, re-read stored token
- interaction-target: identityService.LogoutAsync()
- interaction-target: return await base.SendAsync(newRequest, cancellationToken);

## Coverage

- Symbols: 4
- Executable symbols: 2
- Executable symbols with control flow: 2
- Grounded edges: 4
- Unresolved references: 16
- Control-flow fragments: 2
- Unresolved jumps: 5
- Unsupported constructs: 0
- Control-flow coverage: 100%
- Required diagrams: 2
- Generated diagrams: 4

## Control Flow Fragments

- SendAsync: 90 nodes, 103 edges, 6 jumps, 0 unsupported constructs
- CloneHttpRequestMessageAsync: 26 nodes, 31 edges, 0 jumps, 0 unsupported constructs

## Diagrams

### AuthenticationHeaderHandler Neighborhood

```mermaid
flowchart LR
    class_jvil15_authenticationheaderhandler("AuthenticationHeaderHandler")
    file_17v8pus_authenticationheaderhandler_cs("AuthenticationHeaderHandler")
    method_17fop7p_sendasync[["SendAsync()"]]
    method_oosx7v_clonehttprequestmessageasync[["CloneHttpRequestMessageAsync()"]]
    type_19q79ms_authenticationheaderhandler[/"AuthenticationHeaderHandler"/]
```

### AuthenticationHeaderHandler Execution Overview

```mermaid
flowchart TD
    class_jvil15_authenticationheaderhandler("AuthenticationHeaderHandler")
    method_17fop7p_sendasync[["SendAsync()"]]
    method_oosx7v_clonehttprequestmessageasync[["CloneHttpRequestMessageAsync()"]]
    unresolved_unresolved_13aa5ye_call_target{"Unresolved: IIdentityService.LogoutAsync"}
    unresolved_unresolved_1dv4q1s_call_target{"Unresolved: INativeStorageService.GetSecureString"}
    unresolved_unresolved_1ka6gmw_interaction_target{"Unresolved: identityService.RefreshTokenAsync(); if success, re-read stored token"}
    unresolved_unresolved_1yuzqr3_interaction_target{"Unresolved: identityService.LogoutAsync()"}
    unresolved_unresolved_91bcb5_interaction_target{"Unresolved: return await base.SendAsync(newRequest, cancellationToken);"}
    unresolved_unresolved_cdkxbh_call_target{"Unresolved: CloneHttpRequestMessageAsync"}
    unresolved_unresolved_dhpayi_interaction_target{"Unresolved: protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)"}
    unresolved_unresolved_em137p_interaction_target{"Unresolved: Calls INativeStorageService.GetSecureString to obtain JWT"}
    unresolved_unresolved_m7b2b4_call_target{"Unresolved: IIdentityService.RefreshTokenAsync"}
    unresolved_unresolved_s1379e_interaction_target{"Unresolved: var response = await base.SendAsync(request, cancellationToken);"}
    unresolved_unresolved_vl9u9l_interaction_target{"Unresolved: Delegates to base.SendAsync to perform network call"}
    class_jvil15_authenticationheaderhandler -->|contains| method_17fop7p_sendasync
    class_jvil15_authenticationheaderhandler -->|contains| method_oosx7v_clonehttprequestmessageasync
    class_jvil15_authenticationheaderhandler -->|unresolved interaction| unresolved_unresolved_1ka6gmw_interaction_target
    class_jvil15_authenticationheaderhandler -->|unresolved interaction| unresolved_unresolved_1yuzqr3_interaction_target
    class_jvil15_authenticationheaderhandler -->|unresolved interaction| unresolved_unresolved_91bcb5_interaction_target
    class_jvil15_authenticationheaderhandler -->|unresolved interaction| unresolved_unresolved_dhpayi_interaction_target
    class_jvil15_authenticationheaderhandler -->|unresolved interaction| unresolved_unresolved_em137p_interaction_target
    class_jvil15_authenticationheaderhandler -->|unresolved interaction| unresolved_unresolved_s1379e_interaction_target
    class_jvil15_authenticationheaderhandler -->|unresolved interaction| unresolved_unresolved_vl9u9l_interaction_target
    method_17fop7p_sendasync -->|unresolved call| unresolved_unresolved_13aa5ye_call_target
    method_17fop7p_sendasync -->|unresolved call| unresolved_unresolved_1dv4q1s_call_target
    method_17fop7p_sendasync -->|unresolved call| unresolved_unresolved_1dv4q1s_call_target
    method_17fop7p_sendasync -->|unresolved call| unresolved_unresolved_1dv4q1s_call_target
    method_17fop7p_sendasync -->|unresolved call| unresolved_unresolved_cdkxbh_call_target
    method_17fop7p_sendasync -->|unresolved call| unresolved_unresolved_m7b2b4_call_target
```

### SendAsync() Control Flow

_Warnings: diagram method_17fop7p_sendasync__fragment_diagram exceeds preferred complexity thresholds (90 nodes, 103 edges)._

```mermaid
---
config:
  flowchart:
    defaultRenderer: "elk"
---
flowchart TD
    method_17fop7p_sendasync__call_47_INativeStorageService_GetSecureString[["INativeStorageService.GetSecureString"]]
    method_17fop7p_sendasync__call_64_INativeStorageService_GetSecureString[["INativeStorageService.GetSecureString"]]
    method_17fop7p_sendasync__call_78_IIdentityService_RefreshTokenAsync[["IIdentityService.RefreshTokenAsync"]]
    method_17fop7p_sendasync__call_81_INativeStorageService_GetSecureString[["INativeStorageService.GetSecureString"]]
    method_17fop7p_sendasync__call_87_IIdentityService_LogoutAsync[["IIdentityService.LogoutAsync"]]
    method_17fop7p_sendasync__call_93_CloneHttpRequestMessageAsync[["CloneHttpRequestMessageAsync"]]
    method_17fop7p_sendasync__action_103_sendasync_finally_103_23__finally("Runs cleanup or finalization")
    method_17fop7p_sendasync__action_105_synchronization_105__linear("Release semaphore")
    method_17fop7p_sendasync__action_30_mutation_30__linear("Force browser credentials for SSR")
    method_17fop7p_sendasync__action_32_branch_32__condition{"path contains identity/login|register|refresh"}
    method_17fop7p_sendasync__action_32_branch_32__false("isAuthEndpoint=false")
    method_17fop7p_sendasync__action_32_branch_32__merge("merge")
    method_17fop7p_sendasync__action_32_branch_32__true("isAuthEndpoint=true")
    method_17fop7p_sendasync__action_38_branch_38__condition{"request.RequestUri is local or starts with NavigationManager.BaseUri"}
    method_17fop7p_sendasync__action_38_branch_38__false("isTrustedHost=false")
    method_17fop7p_sendasync__action_38_branch_38__merge("merge")
    method_17fop7p_sendasync__action_38_branch_38__true("isTrustedHost=true")
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__condition{"!isAuthEndpoint && isTrustedHost"}
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__false("false")
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__merge("merge")
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__true("true")
    method_17fop7p_sendasync__action_47_sendasync_await_47_2__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_48_guard_clause_48__condition{"token read succeeded and non-empty"}
    method_17fop7p_sendasync__action_48_guard_clause_48__false("skip-attachment")
    method_17fop7p_sendasync__action_48_guard_clause_48__merge("merge")
    method_17fop7p_sendasync__action_48_guard_clause_48__true("attach-bearer")
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__condition{"tokenResult.IsSuccess && !string.IsNullOrEmpty(tokenResult.Value)"}
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__false("false")
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__merge("merge")
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__true("true")
    method_17fop7p_sendasync__action_55_sendasync_await_55_5__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_58_branch_58__condition{"response.StatusCode == Unauthorized && not an auth endpoint"}
    method_17fop7p_sendasync__action_58_branch_58__false("return-response")
    method_17fop7p_sendasync__action_58_branch_58__merge("merge")
    method_17fop7p_sendasync__action_58_branch_58__true("attempt-refresh")
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__condition{"response.StatusCode == System.Net.HttpStatusCode.Unauthorized && !isAuthEndpoint"}
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__false("false")
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__merge("merge")
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__true("true")
    method_17fop7p_sendasync__action_60_sendasync_await_60_7__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_60_synchronization_60__linear("Semaphore for concurrent refresh")
    method_17fop7p_sendasync__action_61_sendasync_try_61_8__try("Begins protected execution")
    method_17fop7p_sendasync__action_64_sendasync_await_64_9__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_69_branch_69__condition{"currentToken != null && currentToken != originalToken"}
    method_17fop7p_sendasync__action_69_branch_69__false("perform-refresh")
    method_17fop7p_sendasync__action_69_branch_69__merge("merge")
    method_17fop7p_sendasync__action_69_branch_69__true("use-new-token")
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__condition{"!string.IsNullOrEmpty(currentToken) && currentToken != originalToken"}
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__false("false")
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__merge("merge")
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__true("true")
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__condition{"Falls back to alternate path"}
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__false("otherwise")
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__merge("merge")
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__true("fallback")
    method_17fop7p_sendasync__action_76_scope_76__linear("Create service scope for scoped services")
    method_17fop7p_sendasync__action_78_sendasync_await_78_12__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_79_branch_79__condition{"refreshResult.IsSuccess"}
    method_17fop7p_sendasync__action_79_branch_79__false("refreshed=false (logout)")
    method_17fop7p_sendasync__action_79_branch_79__merge("merge")
    method_17fop7p_sendasync__action_79_branch_79__true("refreshed=true (read token)")
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__condition{"refreshResult.IsSuccess"}
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__false("false")
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__merge("merge")
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__true("true")
    method_17fop7p_sendasync__action_81_sendasync_await_81_14__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__condition{"Falls back to alternate path"}
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__false("otherwise")
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__merge("merge")
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__true("fallback")
    method_17fop7p_sendasync__action_87_sendasync_await_87_16__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_91_control_flow_91__linear("Retry original request with refreshed token")
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__condition{"refreshed && !string.IsNullOrEmpty(currentToken)"}
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__false("false")
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__merge("merge")
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__true("true")
    method_17fop7p_sendasync__action_93_sendasync_await_93_18__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_95_sendasync_await_95_20__await[["Waits for async work"]]
    method_17fop7p_sendasync__action_98_error_handling_98__linear("Catch and audit log refresh exceptions")
    method_17fop7p_sendasync__action_98_sendasync_catch_98_22__catch("catch Exception ex")
    method_17fop7p_sendasync__entry(["SendAsync entry"])
    method_17fop7p_sendasync__action_27_sendasync_external_call_27_0__linear("Calls external dependency")
    method_17fop7p_sendasync__action_47_external_call_47__linear("Read stored token")
    method_17fop7p_sendasync__action_55_external_call_55__linear("Send base HTTP request")
    method_17fop7p_sendasync__action_55_sendasync_external_call_55_4__linear("Calls external dependency")
    method_17fop7p_sendasync__action_78_external_call_78__linear("Refresh token via identity service")
    method_17fop7p_sendasync__action_87_external_call_87__linear("Logout on refresh failure")
    method_17fop7p_sendasync__action_95_sendasync_external_call_95_19__linear("Calls external dependency")
    method_17fop7p_sendasync__action_109_sendasync_return_109_24__return(["Returns result"])
    method_17fop7p_sendasync__action_95_sendasync_return_95_21__return(["Returns result"])
    method_17fop7p_sendasync__action_103_sendasync_finally_103_23__finally -->|next| method_17fop7p_sendasync__action_105_synchronization_105__linear
    method_17fop7p_sendasync__action_105_synchronization_105__linear -->|return| method_17fop7p_sendasync__action_109_sendasync_return_109_24__return
    method_17fop7p_sendasync__action_27_sendasync_external_call_27_0__linear -->|next| method_17fop7p_sendasync__action_30_mutation_30__linear
    method_17fop7p_sendasync__action_30_mutation_30__linear -->|next| method_17fop7p_sendasync__action_32_branch_32__condition
    method_17fop7p_sendasync__action_32_branch_32__condition -->|isAuthEndpoint=false| method_17fop7p_sendasync__action_32_branch_32__false
    method_17fop7p_sendasync__action_32_branch_32__condition -->|isAuthEndpoint=true| method_17fop7p_sendasync__action_32_branch_32__true
    method_17fop7p_sendasync__action_32_branch_32__false -->|next| method_17fop7p_sendasync__action_32_branch_32__merge
    method_17fop7p_sendasync__action_32_branch_32__merge -->|next| method_17fop7p_sendasync__action_38_branch_38__condition
    method_17fop7p_sendasync__action_32_branch_32__true -->|next| method_17fop7p_sendasync__action_32_branch_32__merge
    method_17fop7p_sendasync__action_38_branch_38__condition -->|isTrustedHost=false| method_17fop7p_sendasync__action_38_branch_38__false
    method_17fop7p_sendasync__action_38_branch_38__condition -->|isTrustedHost=true| method_17fop7p_sendasync__action_38_branch_38__true
    method_17fop7p_sendasync__action_38_branch_38__false -->|next| method_17fop7p_sendasync__action_38_branch_38__merge
    method_17fop7p_sendasync__action_38_branch_38__merge -->|next| method_17fop7p_sendasync__action_45_sendasync_branch_45_1__condition
    method_17fop7p_sendasync__action_38_branch_38__true -->|next| method_17fop7p_sendasync__action_38_branch_38__merge
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__condition -->|false| method_17fop7p_sendasync__action_45_sendasync_branch_45_1__false
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__condition -->|true| method_17fop7p_sendasync__action_45_sendasync_branch_45_1__true
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__false -->|next| method_17fop7p_sendasync__action_45_sendasync_branch_45_1__merge
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__merge -->|next| method_17fop7p_sendasync__action_47_sendasync_await_47_2__await
    method_17fop7p_sendasync__action_45_sendasync_branch_45_1__true -->|next| method_17fop7p_sendasync__action_45_sendasync_branch_45_1__merge
    method_17fop7p_sendasync__action_47_external_call_47__linear -->|calls| method_17fop7p_sendasync__call_47_INativeStorageService_GetSecureString
    method_17fop7p_sendasync__action_47_sendasync_await_47_2__await -->|next| method_17fop7p_sendasync__action_47_external_call_47__linear
    method_17fop7p_sendasync__action_48_guard_clause_48__condition -->|skip-attachment| method_17fop7p_sendasync__action_48_guard_clause_48__false
    method_17fop7p_sendasync__action_48_guard_clause_48__condition -->|attach-bearer| method_17fop7p_sendasync__action_48_guard_clause_48__true
    method_17fop7p_sendasync__action_48_guard_clause_48__false -->|next| method_17fop7p_sendasync__action_48_guard_clause_48__merge
    method_17fop7p_sendasync__action_48_guard_clause_48__merge -->|next| method_17fop7p_sendasync__action_55_sendasync_await_55_5__await
    method_17fop7p_sendasync__action_48_guard_clause_48__true -->|next| method_17fop7p_sendasync__action_48_guard_clause_48__merge
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__condition -->|false| method_17fop7p_sendasync__action_48_sendasync_branch_48_3__false
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__condition -->|true| method_17fop7p_sendasync__action_48_sendasync_branch_48_3__true
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__false -->|next| method_17fop7p_sendasync__action_48_sendasync_branch_48_3__merge
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__merge -->|next| method_17fop7p_sendasync__action_48_guard_clause_48__condition
    method_17fop7p_sendasync__action_48_sendasync_branch_48_3__true -->|next| method_17fop7p_sendasync__action_48_sendasync_branch_48_3__merge
    method_17fop7p_sendasync__action_55_external_call_55__linear -->|next| method_17fop7p_sendasync__action_55_sendasync_external_call_55_4__linear
    method_17fop7p_sendasync__action_55_sendasync_await_55_5__await -->|next| method_17fop7p_sendasync__action_55_external_call_55__linear
    method_17fop7p_sendasync__action_55_sendasync_external_call_55_4__linear -->|next| method_17fop7p_sendasync__action_58_branch_58__condition
    method_17fop7p_sendasync__action_58_branch_58__condition -->|return-response| method_17fop7p_sendasync__action_58_branch_58__false
    method_17fop7p_sendasync__action_58_branch_58__condition -->|attempt-refresh| method_17fop7p_sendasync__action_58_branch_58__true
    method_17fop7p_sendasync__action_58_branch_58__false -->|next| method_17fop7p_sendasync__action_58_branch_58__merge
    method_17fop7p_sendasync__action_58_branch_58__merge -->|next| method_17fop7p_sendasync__action_58_sendasync_branch_58_6__condition
    method_17fop7p_sendasync__action_58_branch_58__true -->|next| method_17fop7p_sendasync__action_58_branch_58__merge
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__condition -->|false| method_17fop7p_sendasync__action_58_sendasync_branch_58_6__false
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__condition -->|true| method_17fop7p_sendasync__action_58_sendasync_branch_58_6__true
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__false -->|next| method_17fop7p_sendasync__action_58_sendasync_branch_58_6__merge
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__merge -->|next| method_17fop7p_sendasync__action_60_sendasync_await_60_7__await
    method_17fop7p_sendasync__action_58_sendasync_branch_58_6__true -->|next| method_17fop7p_sendasync__action_58_sendasync_branch_58_6__merge
    method_17fop7p_sendasync__action_60_sendasync_await_60_7__await -->|next| method_17fop7p_sendasync__action_60_synchronization_60__linear
    method_17fop7p_sendasync__action_60_synchronization_60__linear -->|next| method_17fop7p_sendasync__action_61_sendasync_try_61_8__try
    method_17fop7p_sendasync__action_61_sendasync_try_61_8__try -->|next| method_17fop7p_sendasync__action_64_sendasync_await_64_9__await
    method_17fop7p_sendasync__action_64_sendasync_await_64_9__await -->|TokenKey to re-read token after detecting 401| method_17fop7p_sendasync__call_64_INativeStorageService_GetSecureString
    method_17fop7p_sendasync__action_69_branch_69__condition -->|perform-refresh| method_17fop7p_sendasync__action_69_branch_69__false
    method_17fop7p_sendasync__action_69_branch_69__condition -->|use-new-token| method_17fop7p_sendasync__action_69_branch_69__true
    method_17fop7p_sendasync__action_69_branch_69__false -->|next| method_17fop7p_sendasync__action_69_branch_69__merge
    method_17fop7p_sendasync__action_69_branch_69__merge -->|fallback| method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__condition
    method_17fop7p_sendasync__action_69_branch_69__true -->|next| method_17fop7p_sendasync__action_69_branch_69__merge
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__condition -->|false| method_17fop7p_sendasync__action_69_sendasync_branch_69_10__false
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__condition -->|true| method_17fop7p_sendasync__action_69_sendasync_branch_69_10__true
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__false -->|next| method_17fop7p_sendasync__action_69_sendasync_branch_69_10__merge
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__merge -->|next| method_17fop7p_sendasync__action_69_branch_69__condition
    method_17fop7p_sendasync__action_69_sendasync_branch_69_10__true -->|next| method_17fop7p_sendasync__action_69_sendasync_branch_69_10__merge
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__condition -->|otherwise| method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__false
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__condition -->|fallback| method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__true
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__false -->|next| method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__merge
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__merge -->|next| method_17fop7p_sendasync__action_76_scope_76__linear
    method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__true -->|next| method_17fop7p_sendasync__action_73_sendasync_fallback_73_11__merge
    method_17fop7p_sendasync__action_76_scope_76__linear -->|next| method_17fop7p_sendasync__action_78_sendasync_await_78_12__await
    method_17fop7p_sendasync__action_78_external_call_78__linear -->|no params triggers refresh flow resolved from scoped provider| method_17fop7p_sendasync__call_78_IIdentityService_RefreshTokenAsync
    method_17fop7p_sendasync__action_78_sendasync_await_78_12__await -->|next| method_17fop7p_sendasync__action_78_external_call_78__linear
    method_17fop7p_sendasync__action_79_branch_79__condition -->|refreshed=false logout| method_17fop7p_sendasync__action_79_branch_79__false
    method_17fop7p_sendasync__action_79_branch_79__condition -->|refreshed=true read token| method_17fop7p_sendasync__action_79_branch_79__true
    method_17fop7p_sendasync__action_79_branch_79__false -->|next| method_17fop7p_sendasync__action_79_branch_79__merge
    method_17fop7p_sendasync__action_79_branch_79__merge -->|next| method_17fop7p_sendasync__action_79_sendasync_branch_79_13__condition
    method_17fop7p_sendasync__action_79_branch_79__true -->|next| method_17fop7p_sendasync__action_79_branch_79__merge
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__condition -->|false| method_17fop7p_sendasync__action_79_sendasync_branch_79_13__false
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__condition -->|true| method_17fop7p_sendasync__action_79_sendasync_branch_79_13__true
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__false -->|next| method_17fop7p_sendasync__action_79_sendasync_branch_79_13__merge
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__merge -->|next| method_17fop7p_sendasync__action_81_sendasync_await_81_14__await
    method_17fop7p_sendasync__action_79_sendasync_branch_79_13__true -->|next| method_17fop7p_sendasync__action_79_sendasync_branch_79_13__merge
    method_17fop7p_sendasync__action_81_sendasync_await_81_14__await -->|TokenKey to read token after refresh| method_17fop7p_sendasync__call_81_INativeStorageService_GetSecureString
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__condition -->|otherwise| method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__false
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__condition -->|fallback| method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__true
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__false -->|next| method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__merge
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__merge -->|next| method_17fop7p_sendasync__action_87_sendasync_await_87_16__await
    method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__true -->|next| method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__merge
    method_17fop7p_sendasync__action_87_external_call_87__linear -->|no params invoked if refresh fails| method_17fop7p_sendasync__call_87_IIdentityService_LogoutAsync
    method_17fop7p_sendasync__action_87_sendasync_await_87_16__await -->|next| method_17fop7p_sendasync__action_87_external_call_87__linear
    method_17fop7p_sendasync__action_91_control_flow_91__linear -->|next| method_17fop7p_sendasync__action_91_sendasync_branch_91_17__condition
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__condition -->|false| method_17fop7p_sendasync__action_91_sendasync_branch_91_17__false
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__condition -->|true| method_17fop7p_sendasync__action_91_sendasync_branch_91_17__true
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__false -->|next| method_17fop7p_sendasync__action_91_sendasync_branch_91_17__merge
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__merge -->|next| method_17fop7p_sendasync__action_93_sendasync_await_93_18__await
    method_17fop7p_sendasync__action_91_sendasync_branch_91_17__true -->|next| method_17fop7p_sendasync__action_91_sendasync_branch_91_17__merge
    method_17fop7p_sendasync__action_93_sendasync_await_93_18__await -->|original HttpRequestMessage to produce a resendable clone| method_17fop7p_sendasync__call_93_CloneHttpRequestMessageAsync
    method_17fop7p_sendasync__action_95_sendasync_await_95_20__await -->|return| method_17fop7p_sendasync__action_95_sendasync_return_95_21__return
    method_17fop7p_sendasync__action_95_sendasync_external_call_95_19__linear -->|exception| method_17fop7p_sendasync__action_98_sendasync_catch_98_22__catch
    method_17fop7p_sendasync__action_95_sendasync_return_95_21__return -->|next| method_17fop7p_sendasync__action_95_sendasync_external_call_95_19__linear
    method_17fop7p_sendasync__action_98_error_handling_98__linear -->|next| method_17fop7p_sendasync__action_103_sendasync_finally_103_23__finally
    method_17fop7p_sendasync__action_98_sendasync_catch_98_22__catch -->|next| method_17fop7p_sendasync__action_98_error_handling_98__linear
    method_17fop7p_sendasync__call_47_INativeStorageService_GetSecureString -->|next| method_17fop7p_sendasync__action_48_sendasync_branch_48_3__condition
    method_17fop7p_sendasync__call_64_INativeStorageService_GetSecureString -->|next| method_17fop7p_sendasync__action_69_sendasync_branch_69_10__condition
    method_17fop7p_sendasync__call_78_IIdentityService_RefreshTokenAsync -->|next| method_17fop7p_sendasync__action_79_branch_79__condition
    method_17fop7p_sendasync__call_81_INativeStorageService_GetSecureString -->|fallback| method_17fop7p_sendasync__action_85_sendasync_fallback_85_15__condition
    method_17fop7p_sendasync__call_87_IIdentityService_LogoutAsync -->|next| method_17fop7p_sendasync__action_91_control_flow_91__linear
    method_17fop7p_sendasync__call_93_CloneHttpRequestMessageAsync -->|next| method_17fop7p_sendasync__action_95_sendasync_await_95_20__await
    method_17fop7p_sendasync__entry -->|next| method_17fop7p_sendasync__action_27_sendasync_external_call_27_0__linear
```

### CloneHttpRequestMessageAsync() Control Flow

_Warnings: diagram method_oosx7v_clonehttprequestmessageasync__fragment_diagram exceeds preferred complexity thresholds (26 nodes, 31 edges)._

```mermaid
---
config:
  flowchart:
    defaultRenderer: "elk"
---
flowchart TD
    method_oosx7v_clonehttprequestmessageasync__action_114_construction_114__linear("Create new HttpRequestMessage clone")
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__condition{"req.Content != null"}
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__false("no-content")
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__merge("merge")
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__true("copy-content")
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__condition{"req.Content != null"}
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__false("false")
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__merge("merge")
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__true("true")
    method_oosx7v_clonehttprequestmessageasync__action_121_io_121__linear("Copy content stream")
    method_oosx7v_clonehttprequestmessageasync__action_122_clonehttprequestmessageasync_await_122_1__await[["Waits for async work"]]
    method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_body[["foreach (var h in req.Content.Headers)"]]
    method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_entry("var h in req.Content.Headers")
    method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_exit("Leaves the loop when the condition no longer holds.")
    method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_body[["foreach over req.Content.Headers and TryAddWithoutValidation onto clone.Content.Headers"]]
    method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_entry("Copy content headers")
    method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_exit("exit loop")
    method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_body[["foreach (var h in req.Headers)"]]
    method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_entry("var h in req.Headers")
    method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_exit("Leaves the loop when the condition no longer holds.")
    method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_body[["foreach over req.Headers and TryAddWithoutValidation onto clone.Headers"]]
    method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_entry("Copy request headers")
    method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_exit("exit loop")
    method_oosx7v_clonehttprequestmessageasync__action_137_mutation_137__linear("Preserve browser credentials")
    method_oosx7v_clonehttprequestmessageasync__entry(["CloneHttpRequestMessageAsync entry"])
    method_oosx7v_clonehttprequestmessageasync__action_139_clonehttprequestmessageasync_return_139_4__return(["Returns result"])
    method_oosx7v_clonehttprequestmessageasync__action_114_construction_114__linear -->|next| method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__condition
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__condition -->|no-content| method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__false
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__condition -->|copy-content| method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__true
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__false -->|next| method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__merge
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__merge -->|next| method_oosx7v_clonehttprequestmessageasync__action_121_io_121__linear
    method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__true -->|next| method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__merge
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__condition -->|false| method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__false
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__condition -->|true| method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__true
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__false -->|next| method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__merge
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__merge -->|next| method_oosx7v_clonehttprequestmessageasync__action_119_branch_119__condition
    method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__true -->|next| method_oosx7v_clonehttprequestmessageasync__action_119_clonehttprequestmessageasync_branch_119_0__merge
    method_oosx7v_clonehttprequestmessageasync__action_121_io_121__linear -->|next| method_oosx7v_clonehttprequestmessageasync__action_122_clonehttprequestmessageasync_await_122_1__await
    method_oosx7v_clonehttprequestmessageasync__action_122_clonehttprequestmessageasync_await_122_1__await -->|next| method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_entry
    method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_body -->|continue| method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_entry
    method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_entry -->|var h in req.Content.Headers| method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_body
    method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_entry -->|Leaves the loop when the condition no longer holds.| method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_exit
    method_oosx7v_clonehttprequestmessageasync__action_126_clonehttprequestmessageasync_loop_126_2__loop_exit -->|next| method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_entry
    method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_body -->|continue| method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_entry
    method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_entry -->|iterate| method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_body
    method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_entry -->|exit| method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_exit
    method_oosx7v_clonehttprequestmessageasync__action_126_loop_126__loop_exit -->|next| method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_entry
    method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_body -->|continue| method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_entry
    method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_entry -->|var h in req.Headers| method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_body
    method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_entry -->|Leaves the loop when the condition no longer holds.| method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_exit
    method_oosx7v_clonehttprequestmessageasync__action_132_clonehttprequestmessageasync_loop_132_3__loop_exit -->|next| method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_entry
    method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_body -->|continue| method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_entry
    method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_entry -->|iterate| method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_body
    method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_entry -->|exit| method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_exit
    method_oosx7v_clonehttprequestmessageasync__action_132_loop_132__loop_exit -->|next| method_oosx7v_clonehttprequestmessageasync__action_137_mutation_137__linear
    method_oosx7v_clonehttprequestmessageasync__action_137_mutation_137__linear -->|return| method_oosx7v_clonehttprequestmessageasync__action_139_clonehttprequestmessageasync_return_139_4__return
    method_oosx7v_clonehttprequestmessageasync__entry -->|next| method_oosx7v_clonehttprequestmessageasync__action_114_construction_114__linear
```

## Diagram Validation

- Status: warn
- Warning: Control-flow extraction left 5 unresolved jumps.
- Warning: control-flow: diagram method_17fop7p_sendasync__fragment_diagram exceeds preferred complexity thresholds (90 nodes, 103 edges).
- Warning: control-flow: diagram method_oosx7v_clonehttprequestmessageasync__fragment_diagram exceeds preferred complexity thresholds (26 nodes, 31 edges).
