`${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorizing identifier ${truncateId(identifier.value)} via OCPP 2.0 Authorize`
)
- // Check if remote authorization is configured
const isRemoteAuth = this.isRemoteAvailable()
if (!isRemoteAuth) {
return {
}
}
- try {
- const idToken = this.convertFromIdentifier(identifier)
-
- // Validate token format
- const isValidToken = this.isValidIdentifier(identifier)
- if (!isValidToken) {
- return {
- additionalInfo: {
- connectorId,
- error: 'Invalid token format for OCPP 2.0',
- transactionId,
- },
- isOffline: false,
- method: AuthenticationMethod.REMOTE_AUTHORIZATION,
- status: AuthorizationStatus.INVALID,
- timestamp: new Date(),
- }
- }
-
- logger.debug(
- `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Sending Authorize request (idToken: ${idToken.idToken})`
- )
-
- // Send Authorize request
- const response = await this.chargingStation.ocppRequestService.requestHandler<
- OCPP20AuthorizeRequest,
- OCPP20AuthorizeResponse
- >(this.chargingStation, OCPP20RequestCommand.AUTHORIZE, {
- idToken,
- })
-
- // Extract authorization status from response
- const authStatus = response.idTokenInfo.status
- const cacheExpiryDateTime = response.idTokenInfo.cacheExpiryDateTime
-
- // Map OCPP 2.0 authorization status
- const mappedStatus = mapOCPP20AuthorizationStatus(authStatus)
-
- logger.debug(
- `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorization result for ${idToken.idToken}: ${authStatus} (mapped: ${mappedStatus})`
- )
-
- return {
- additionalInfo: {
- cacheExpiryDateTime,
- chargingPriority: response.idTokenInfo.chargingPriority,
- connectorId,
- ocpp20Status: authStatus,
- tokenType: idToken.type,
- tokenValue: idToken.idToken,
- },
- isOffline: false,
- method: AuthenticationMethod.REMOTE_AUTHORIZATION,
- status: mappedStatus,
- timestamp: new Date(),
- }
- } catch (error) {
- logger.error(
- `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorize request failed`,
- error
- )
+ const idToken = this.convertFromIdentifier(identifier)
+ const isValidToken = this.isValidIdentifier(identifier)
+ if (!isValidToken) {
return {
additionalInfo: {
connectorId,
- error: error instanceof Error ? error.message : 'Unknown error',
+ error: 'Invalid token format for OCPP 2.0',
transactionId,
},
isOffline: false,
timestamp: new Date(),
}
}
+
+ logger.debug(
+ `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Sending Authorize request (idToken: ${idToken.idToken})`
+ )
+
+ const response = await this.chargingStation.ocppRequestService.requestHandler<
+ OCPP20AuthorizeRequest,
+ OCPP20AuthorizeResponse
+ >(this.chargingStation, OCPP20RequestCommand.AUTHORIZE, {
+ idToken,
+ })
+
+ const authStatus = response.idTokenInfo.status
+ const cacheExpiryDateTime = response.idTokenInfo.cacheExpiryDateTime
+
+ const mappedStatus = mapOCPP20AuthorizationStatus(authStatus)
+
+ logger.debug(
+ `${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Authorization result for ${idToken.idToken}: ${authStatus} (mapped: ${mappedStatus})`
+ )
+
+ return {
+ additionalInfo: {
+ cacheExpiryDateTime,
+ chargingPriority: response.idTokenInfo.chargingPriority,
+ connectorId,
+ ocpp20Status: authStatus,
+ tokenType: idToken.type,
+ tokenValue: idToken.idToken,
+ },
+ isOffline: false,
+ method: AuthenticationMethod.REMOTE_AUTHORIZATION,
+ status: mappedStatus,
+ timestamp: new Date(),
+ }
} catch (error) {
logger.error(
`${this.chargingStation.logPrefix()} ${moduleName}.${methodName}: Remote authorization failed`,
})
await describe('default behavior', async () => {
- await it('should be no-op when DisablePostAuthorize not configured (default behavior preserved)', async () => {
+ await it('should trigger re-auth when DisablePostAuthorize not configured (defaults to enabled)', async () => {
// Arrange
const blockedResult = createMockAuthorizationResult({
method: AuthenticationMethod.CACHE,
// Act
const result = await strategy.authenticate(request, config)
- // Assert - returns cached result as-is (disablePostAuthorize not in config)
- assert.notStrictEqual(result, undefined)
- assert.strictEqual(result?.status, AuthorizationStatus.BLOCKED)
+ // Assert - undefined signals orchestrator should try remote strategy (C10.FR.03)
+ assert.strictEqual(result, undefined)
})
})
})