Skip to content

Commit

Permalink
differentOwner for deviceAuthenticationMode === PRE_SHARED_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikMatiasko committed Sep 3, 2023
1 parent 999a932 commit 9f67cf7
Showing 1 changed file with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,33 @@ const RemoteClientsPage: FC<Props> = (props) => {
[wellKnownConfig, clientData]
)

const differentOwner = useCallback((wellKnownConfig?: WellKnownConfigType) => {
if (!wellKnownConfig?.isInitialized) {
return false
}

const accessToken = security.getAccessToken()

if (accessToken && wellKnownConfig) {
const parsedData = jwtDecode(accessToken)
const ownerId = get(parsedData, wellKnownConfig?.remoteProvisioning?.jwtOwnerClaim as string, '')
const differentOwner = useCallback(
(wellKnownConfig?: WellKnownConfigType) => {
if (!wellKnownConfig || !wellKnownConfig?.isInitialized) {
return false
}

if (ownerId !== wellKnownConfig?.owner) {
return true
if (wellKnownConfig?.deviceAuthenticationMode === DEVICE_AUTH_MODE.PRE_SHARED_KEY && clientData.preSharedSubjectId) {
if (wellKnownConfig.owner !== clientData.preSharedSubjectId) {
return true
}
} else if (wellKnownConfig?.deviceAuthenticationMode === DEVICE_AUTH_MODE.X509) {
const accessToken = security.getAccessToken()

if (accessToken) {
const parsedData = jwtDecode(accessToken)
const ownerId = get(parsedData, wellKnownConfig?.remoteProvisioning?.jwtOwnerClaim as string, '')

if (ownerId !== wellKnownConfig?.owner) {
return true
}
}
}
}

return false
}, [])
return false
},
[clientData.preSharedSubjectId]
)

useEffect(() => {
clientAppSettings.setUseToken(!differentOwner(wellKnownConfig) && clientData.authenticationMode === DEVICE_AUTH_MODE.X509)
Expand Down

0 comments on commit 9f67cf7

Please sign in to comment.