/// <summary> /// Makes a TS call to do device authentication. /// </summary> /// <param name="context">The request context.</param> /// <param name="deviceToken">The device token.</param> /// <returns>Authenticated device.</returns> internal static Device AuthenticateDevice(RequestContext context, string deviceToken) { var serviceRequest = new AuthenticateDeviceServiceRequest(deviceToken); AuthenticateDeviceServiceResponse serviceResponse = context.Execute <AuthenticateDeviceServiceResponse>(serviceRequest); return(serviceResponse.Device); }
/// <summary> /// Authenticates the device. /// </summary> /// <param name="request">The device authentication request.</param> /// <returns>The response.</returns> private static AuthenticateDeviceServiceResponse AuthenticateDevice(AuthenticateDeviceServiceRequest request) { Device device = new Device(); if (string.IsNullOrWhiteSpace(request.Token)) { throw new ArgumentException("request.Token is not set", "request"); } device = ConstructDeviceFromToken(request.Token); try { // Try to validate the device token using the channel database device = ValidateDeviceTokenLocally(device.DeviceNumber, device.TokenData, request.Token, request.RequestContext); } catch (DeviceAuthenticationException deviceAuthenticationException) { RetailLogger.Log.CrtServicesDeviceManagementServiceDeviceAuthenticationInChannelDbFailure(device.ToString(), deviceAuthenticationException); try { // If local authentication failed then try to contact AX for activation and refresh local data. AuthenticateDeviceRealtimeRequest realtimeRequest = new AuthenticateDeviceRealtimeRequest(device); device = request.RequestContext.Execute <AuthenticateDeviceRealtimeResponse>(realtimeRequest).Device; } catch (HeadquarterTransactionServiceException ex) { RetailLogger.Log.CrtServicesDeviceManagementServiceDeviceAuthenticationInAxFailure(device.ToString(), ex); throw new DeviceAuthenticationException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_HeadquarterTransactionServiceMethodCallFailure, ex, ex.Message) { LocalizedMessage = ex.LocalizedMessage }; } // Creating or updating the authenticated device in the channel db. CreateOrUpdateDeviceDataRequest createOrUpdateDeviceDataRequest = new CreateOrUpdateDeviceDataRequest(device); request.RequestContext.Execute <NullResponse>(createOrUpdateDeviceDataRequest); } return(new AuthenticateDeviceServiceResponse(device)); }