last ...
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MongoDB.Bson;
|
||||
using xCommons.Constants;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xHttpService.Constants;
|
||||
using xIdentityModels.Dtos;
|
||||
using xIdentityService.Constants;
|
||||
using xModels.Dtos;
|
||||
using xModels.Extensions;
|
||||
|
||||
namespace xIdentityService.Providers
|
||||
{
|
||||
public partial class XIdentityProvider
|
||||
{
|
||||
public async Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||
XDeviceDto device,
|
||||
string userSelectByParam
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
validationProvider.NotNull(device);
|
||||
validationProvider.NotEmpty(userSelectByParam);
|
||||
|
||||
//
|
||||
// Prepare Open Action Model ...
|
||||
var opaModel = new XOpenActionRequestDto
|
||||
{
|
||||
Device = device,
|
||||
Payload = userSelectByParam,
|
||||
Action = XOpenActions.GetUserInfo,
|
||||
Timestamp = DateTime.UtcNow.AddMinutes(5)
|
||||
};
|
||||
if (!opaModel.Validate())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Fill Checksum Filed ...
|
||||
var token = opaModel.ToOpenActionToken();
|
||||
opaModel.Checksum = token;
|
||||
|
||||
//
|
||||
// Prepare Request ...
|
||||
var opaJson = opaModel.ToJson();
|
||||
var requestString = SecurityProvider.Encrypt(opaJson);
|
||||
|
||||
//
|
||||
return await GetUserInfo(
|
||||
token: token,
|
||||
request: requestString
|
||||
);
|
||||
}
|
||||
|
||||
public async Task<XOpenActionUserInfoDto> GetUserInfo(XOpenActionInnerDto dto)
|
||||
{
|
||||
//
|
||||
return await GetUserInfo(
|
||||
token: dto.Token,
|
||||
request: dto.Payload
|
||||
);
|
||||
}
|
||||
|
||||
public async Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||
string token,
|
||||
string request
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
validationProvider.NotEmpty(token);
|
||||
validationProvider.NotEmpty(request);
|
||||
|
||||
//
|
||||
// Retrieve Rest Client ...
|
||||
var client = GetRestClient();
|
||||
|
||||
//
|
||||
// Prepare Rest Request ...
|
||||
var requestU = GetRestRequet(
|
||||
XApiAccountEndpoint.GetUserInfo,
|
||||
@params: new Dictionary<string, string>
|
||||
{
|
||||
{ XParam.XRequest.GetStringValue(), request }
|
||||
},
|
||||
headers: new Dictionary<string, string>
|
||||
{
|
||||
{ XAuthentication.TOKEN, token}
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequestByResponse<string>(
|
||||
client,
|
||||
requestU,
|
||||
XHttpMethod.GET
|
||||
);
|
||||
|
||||
//
|
||||
// Now we Have to Validate the recieved response ...
|
||||
|
||||
//
|
||||
// Read token from Headers ...
|
||||
|
||||
//
|
||||
var responseToken = response.Response.Headers.First(h => h.Name == XAuthentication.TOKEN).ToString();
|
||||
if (responseToken.IsNullOrEmpty())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var responseJson = SecurityProvider.Decrypt(response.Model);
|
||||
if (responseJson.IsNullOrEmpty())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Model and Validate it ...
|
||||
var responseModel = responseJson.FromJSON<XOpenActionRequestDto>();
|
||||
if (responseModel.IsNull() ||
|
||||
responseModel.Timestamp.IsExPired() ||
|
||||
responseModel.Payload.IsNullOrEmpty() ||
|
||||
// !responseModel.Device.IsSameAs(device) ||
|
||||
responseToken != responseModel.Checksum)
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Retrieve Model ...
|
||||
var result = responseModel.Payload.FromJSON<XOpenActionUserInfoDto>();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user