public async Task <ChannelIdentifier> AuthorizeDevice(HttpContext httpContext) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (!httpContext.Request.Headers.TryGetValue(CloudHeaderNames.ChannelAccessToken, out var channelAccessToken)) { throw new UnauthorizedAccessException(); } var identityEntity = await _repositoryService.FindIdentityEntityByChannelAccessToken(channelAccessToken).ConfigureAwait(false); if (identityEntity.Key == null) { throw new UnauthorizedAccessException(); } if (identityEntity.Value.IsLocked) { throw new UnauthorizedAccessException(); } var channelEntity = identityEntity.Value.Channels.First(c => string.Equals(c.Value.AccessToken.Value, channelAccessToken, StringComparison.Ordinal)); if (channelEntity.Key == null) { throw new UnauthorizedAccessException(); } return(new ChannelIdentifier(identityEntity.Key, channelEntity.Key)); }