• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

damienbod / angular-auth-oidc-client / 9308899843

30 May 2024 08:37PM CUT coverage: 92.928%. Remained the same
9308899843

Pull #1948

github

web-flow
Merge 9ccb2c964 into 33372edf1
Pull Request #1948: feat(core): adds angular 18 support

706 of 826 branches covered (85.47%)

Branch coverage included in aggregate %.

2566 of 2695 relevant lines covered (95.21%)

8.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.94
/projects/angular-auth-oidc-client/src/lib/flows/flows-data.service.ts
1
import { Injectable, inject } from '@angular/core';
2
import { OpenIdConfiguration } from '../config/openid-configuration';
3
import { LoggerService } from '../logging/logger.service';
4
import { StoragePersistenceService } from '../storage/storage-persistence.service';
5
import { SilentRenewRunning } from './flows.models';
6
import { RandomService } from './random/random.service';
7

8
@Injectable({ providedIn: 'root' })
9
export class FlowsDataService {
1✔
10
  private readonly loggerService = inject(LoggerService);
19✔
11

12
  private readonly storagePersistenceService = inject(
19✔
13
    StoragePersistenceService
14
  );
15

16
  private readonly randomService = inject(RandomService);
19✔
17

18
  createNonce(configuration: OpenIdConfiguration): string {
19
    const nonce = this.randomService.createRandom(40, configuration);
1✔
20

21
    this.loggerService.logDebug(configuration, 'Nonce created. nonce:' + nonce);
1✔
22
    this.setNonce(nonce, configuration);
1✔
23

24
    return nonce;
1✔
25
  }
26

27
  setNonce(nonce: string, configuration: OpenIdConfiguration): void {
28
    this.storagePersistenceService.write('authNonce', nonce, configuration);
1✔
29
  }
30

31
  getAuthStateControl(configuration: OpenIdConfiguration | null): string {
32
    if (!configuration) {
1!
33
      return '';
×
34
    }
35

36
    return this.storagePersistenceService.read(
1✔
37
      'authStateControl',
38
      configuration
39
    );
40
  }
41

42
  setAuthStateControl(
43
    authStateControl: string,
44
    configuration: OpenIdConfiguration | null
45
  ): boolean {
46
    if (!configuration) {
1!
47
      return false;
×
48
    }
49

50
    return this.storagePersistenceService.write(
1✔
51
      'authStateControl',
52
      authStateControl,
53
      configuration
54
    );
55
  }
56

57
  getExistingOrCreateAuthStateControl(configuration: OpenIdConfiguration): any {
58
    let state = this.storagePersistenceService.read(
2✔
59
      'authStateControl',
60
      configuration
61
    );
62

63
    if (!state) {
2✔
64
      state = this.randomService.createRandom(40, configuration);
1✔
65
      this.storagePersistenceService.write(
1✔
66
        'authStateControl',
67
        state,
68
        configuration
69
      );
70
    }
71

72
    return state;
2✔
73
  }
74

75
  setSessionState(sessionState: any, configuration: OpenIdConfiguration): void {
76
    this.storagePersistenceService.write(
1✔
77
      'session_state',
78
      sessionState,
79
      configuration
80
    );
81
  }
82

83
  resetStorageFlowData(configuration: OpenIdConfiguration): void {
84
    this.storagePersistenceService.resetStorageFlowData(configuration);
1✔
85
  }
86

87
  getCodeVerifier(configuration: OpenIdConfiguration): any {
88
    return this.storagePersistenceService.read('codeVerifier', configuration);
1✔
89
  }
90

91
  createCodeVerifier(configuration: OpenIdConfiguration): string {
92
    const codeVerifier = this.randomService.createRandom(67, configuration);
1✔
93

94
    this.storagePersistenceService.write(
1✔
95
      'codeVerifier',
96
      codeVerifier,
97
      configuration
98
    );
99

100
    return codeVerifier;
1✔
101
  }
102

103
  isCodeFlowInProgress(configuration: OpenIdConfiguration): boolean {
104
    return !!this.storagePersistenceService.read(
2✔
105
      'storageCodeFlowInProgress',
106
      configuration
107
    );
108
  }
109

110
  setCodeFlowInProgress(configuration: OpenIdConfiguration): void {
111
    this.storagePersistenceService.write(
1✔
112
      'storageCodeFlowInProgress',
113
      true,
114
      configuration
115
    );
116
  }
117

118
  resetCodeFlowInProgress(configuration: OpenIdConfiguration): void {
119
    this.storagePersistenceService.write(
1✔
120
      'storageCodeFlowInProgress',
121
      false,
122
      configuration
123
    );
124
  }
125

126
  isSilentRenewRunning(configuration: OpenIdConfiguration): boolean {
127
    const { configId, silentRenewTimeoutInSeconds } = configuration;
3✔
128
    const storageObject = this.getSilentRenewRunningStorageEntry(configuration);
3✔
129

130
    if (!storageObject) {
3!
131
      return false;
×
132
    }
133

134
    if (storageObject.state === 'not-running') {
3✔
135
      return false;
1✔
136
    }
137

138
    const timeOutInMilliseconds = (silentRenewTimeoutInSeconds ?? 0) * 1000;
2!
139
    const dateOfLaunchedProcessUtc = Date.parse(
2✔
140
      storageObject.dateOfLaunchedProcessUtc
141
    );
142
    const currentDateUtc = Date.parse(new Date().toISOString());
2✔
143
    const elapsedTimeInMilliseconds = Math.abs(
2✔
144
      currentDateUtc - dateOfLaunchedProcessUtc
145
    );
146
    const isProbablyStuck = elapsedTimeInMilliseconds > timeOutInMilliseconds;
2✔
147

148
    if (isProbablyStuck) {
2✔
149
      this.loggerService.logDebug(
1✔
150
        configuration,
151
        'silent renew process is probably stuck, state will be reset.',
152
        configId
153
      );
154
      this.resetSilentRenewRunning(configuration);
1✔
155

156
      return false;
1✔
157
    }
158

159
    return storageObject.state === 'running';
1✔
160
  }
161

162
  setSilentRenewRunning(configuration: OpenIdConfiguration): void {
163
    const storageObject: SilentRenewRunning = {
1✔
164
      state: 'running',
165
      dateOfLaunchedProcessUtc: new Date().toISOString(),
166
    };
167

168
    this.storagePersistenceService.write(
1✔
169
      'storageSilentRenewRunning',
170
      JSON.stringify(storageObject),
171
      configuration
172
    );
173
  }
174

175
  resetSilentRenewRunning(configuration: OpenIdConfiguration | null): void {
176
    if (!configuration) {
2!
177
      return;
×
178
    }
179

180
    this.storagePersistenceService.write(
2✔
181
      'storageSilentRenewRunning',
182
      '',
183
      configuration
184
    );
185
  }
186

187
  private getSilentRenewRunningStorageEntry(
188
    configuration: OpenIdConfiguration
189
  ): SilentRenewRunning {
190
    const storageEntry = this.storagePersistenceService.read(
3✔
191
      'storageSilentRenewRunning',
192
      configuration
193
    );
194

195
    if (!storageEntry) {
3✔
196
      return {
1✔
197
        dateOfLaunchedProcessUtc: '',
198
        state: 'not-running',
199
      };
200
    }
201

202
    return JSON.parse(storageEntry);
2✔
203
  }
204
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc