last ...
This commit is contained in:
@@ -198,8 +198,8 @@ namespace xIdentityService.Constants
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Open Actions ...
|
#region Open Actions ...
|
||||||
[StringValue("Account/GetUserInfo")]
|
[StringValue("Open")]
|
||||||
GetUserInfo,
|
Open,
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,12 +285,33 @@ namespace xIdentityService.Interfaces
|
|||||||
|
|
||||||
//
|
//
|
||||||
#region Open Actions ...
|
#region Open Actions ...
|
||||||
|
//
|
||||||
|
Task<XOpenActionInnerDto> OpenGet(
|
||||||
|
XOpenActionInnerDto model
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
Task<XOpenActionUserInfoDto> GetUserInfo(
|
Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||||
XDeviceDto device,
|
XDeviceDto device,
|
||||||
string userSelectByParam
|
string userSelectByParam
|
||||||
);
|
);
|
||||||
Task<XOpenActionUserInfoDto> GetUserInfo(XOpenActionInnerDto dto);
|
|
||||||
Task<XOpenActionUserInfoDto> GetUserInfo(
|
Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||||
|
XOpenActionInnerDto dto
|
||||||
|
);
|
||||||
|
Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||||
|
string token,
|
||||||
|
string request
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
Task<IEnumerable<XOpenActionUserInfoDto>> GetUserInfos(
|
||||||
|
XDeviceDto device,
|
||||||
|
string ids
|
||||||
|
);
|
||||||
|
Task<IEnumerable<XOpenActionUserInfoDto>> GetUserInfos(
|
||||||
|
XOpenActionInnerDto dto
|
||||||
|
);
|
||||||
|
Task<IEnumerable<XOpenActionUserInfoDto>> GetUserInfos(
|
||||||
string token,
|
string token,
|
||||||
string request
|
string request
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,6 +15,114 @@ namespace xIdentityService.Providers
|
|||||||
{
|
{
|
||||||
public partial class XIdentityProvider
|
public partial class XIdentityProvider
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
#region OpenGet ...
|
||||||
|
public async Task<XOpenActionInnerDto> OpenGet(
|
||||||
|
XOpenActionInnerDto model
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
await validationProvider
|
||||||
|
.GroupValidationBuilder()
|
||||||
|
.AddNotNull(model)
|
||||||
|
.AddNotEmpty(model.Token)
|
||||||
|
.AddNotEmpty(model.Payload)
|
||||||
|
.ValidateGroupAsync();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await OpenGet(
|
||||||
|
token: model.Token,
|
||||||
|
actionRequest: model.Payload
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public async Task<XOpenActionInnerDto> OpenGet(
|
||||||
|
string token,
|
||||||
|
string actionRequest
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
await validationProvider
|
||||||
|
.GroupValidationBuilder()
|
||||||
|
.AddNotEmpty(token)
|
||||||
|
.AddNotEmpty(actionRequest)
|
||||||
|
.ValidateGroupAsync();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Rest Client ...
|
||||||
|
var client = GetRestClient();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Rest Request ...
|
||||||
|
var request = GetRestRequet(
|
||||||
|
XApiAccountEndpoint.Open,
|
||||||
|
headers: new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ XAuthentication.TOKEN, token}
|
||||||
|
},
|
||||||
|
queryStrings: new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ XParam.XRequest.GetStringValue(), actionRequest }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Run Request and Retrieve Response ...
|
||||||
|
var response = await RunRestRequestByResponse<string>(
|
||||||
|
client,
|
||||||
|
request,
|
||||||
|
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).Value.ToString();
|
||||||
|
if (responseToken.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Decript Recieve Response ...
|
||||||
|
var responseJson = SecurityProvider.Decrypt(response.Model);
|
||||||
|
if (responseJson.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = new XOpenActionInnerDto
|
||||||
|
{
|
||||||
|
Token = responseToken,
|
||||||
|
Payload = responseJson
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Model and Validate it ...
|
||||||
|
var responseModel = responseJson.FromJSON<XOpenActionRequestDto>();
|
||||||
|
if (responseModel.IsNull() ||
|
||||||
|
responseModel.Payload.IsNullOrEmpty() ||
|
||||||
|
responseToken != responseModel.Checksum ||
|
||||||
|
responseModel.Timestamp.FromTimestamp().IsExPired())
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region GetUserInfo ...
|
||||||
public async Task<XOpenActionUserInfoDto> GetUserInfo(
|
public async Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||||
XDeviceDto device,
|
XDeviceDto device,
|
||||||
string userSelectByParam
|
string userSelectByParam
|
||||||
@@ -32,7 +140,7 @@ namespace xIdentityService.Providers
|
|||||||
Device = device,
|
Device = device,
|
||||||
Payload = userSelectByParam,
|
Payload = userSelectByParam,
|
||||||
Action = XOpenActions.GetUserInfo,
|
Action = XOpenActions.GetUserInfo,
|
||||||
Timestamp = DateTime.UtcNow.AddMinutes(5).ToTimestamp()
|
Timestamp = DateTime.UtcNow.AddMinutes(5).ToTimestamp().ToString()
|
||||||
};
|
};
|
||||||
if (!opaModel.Validate())
|
if (!opaModel.Validate())
|
||||||
{
|
{
|
||||||
@@ -56,7 +164,9 @@ namespace xIdentityService.Providers
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<XOpenActionUserInfoDto> GetUserInfo(XOpenActionInnerDto dto)
|
public async Task<XOpenActionUserInfoDto> GetUserInfo(
|
||||||
|
XOpenActionInnerDto dto
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
return await GetUserInfo(
|
return await GetUserInfo(
|
||||||
@@ -76,68 +186,123 @@ namespace xIdentityService.Providers
|
|||||||
validationProvider.NotEmpty(request);
|
validationProvider.NotEmpty(request);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Retrieve Rest Client ...
|
// Retrieve and Validate Response ...
|
||||||
var client = GetRestClient();
|
var response = await OpenGet(
|
||||||
|
token: token,
|
||||||
//
|
actionRequest: request
|
||||||
// Prepare Rest Request ...
|
|
||||||
var requestU = GetRestRequet(
|
|
||||||
XApiAccountEndpoint.GetUserInfo,
|
|
||||||
headers: new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ XAuthentication.TOKEN, token}
|
|
||||||
},
|
|
||||||
queryStrings: new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ XParam.XRequest.GetStringValue(), request }
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
if (response.IsNull() ||
|
||||||
//
|
response.Token.IsNullOrEmpty() ||
|
||||||
var response = await RunRestRequestByResponse<string>(
|
response.Payload.IsNullOrEmpty())
|
||||||
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();
|
XException.ActionFailed.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var responseJson = SecurityProvider.Decrypt(response.Model);
|
// Now we Have to Converts Repose Payload to Result Model ...
|
||||||
if (responseJson.IsNullOrEmpty())
|
// Note that the respose Model's payload here is Decrypted and
|
||||||
|
// actually is Json Representation of Result Model ...
|
||||||
|
var result = response.Payload.FromJSON<XOpenActionUserInfoDto>();
|
||||||
|
if (result.IsNull())
|
||||||
{
|
{
|
||||||
XException.ActionFailed.Throw();
|
XException.ActionFailed.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Model and Validate it ...
|
|
||||||
var responseModel = responseJson.FromJSON<XOpenActionRequestDto>();
|
|
||||||
if (responseModel.IsNull() ||
|
|
||||||
responseModel.Payload.IsNullOrEmpty() ||
|
|
||||||
// !responseModel.Device.IsSameAs(device) ||
|
|
||||||
responseToken != responseModel.Checksum ||
|
|
||||||
responseModel.Timestamp.FromTimestamp().IsExPired())
|
|
||||||
{
|
|
||||||
XException.ActionFailed.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Try to Retrieve Model ...
|
|
||||||
var result = responseModel.Payload.FromJSON<XOpenActionUserInfoDto>();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region GetUserInfos ...
|
||||||
|
public async Task<IEnumerable<XOpenActionUserInfoDto>> GetUserInfos(
|
||||||
|
XDeviceDto device,
|
||||||
|
string ids
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
validationProvider.NotNull(device);
|
||||||
|
validationProvider.NotEmpty(ids);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Open Action Model ...
|
||||||
|
var opaModel = new XOpenActionRequestDto
|
||||||
|
{
|
||||||
|
Payload = ids,
|
||||||
|
Device = device,
|
||||||
|
Action = XOpenActions.GetUserInfos,
|
||||||
|
Timestamp = DateTime.UtcNow.AddMinutes(5).ToTimestamp().ToString()
|
||||||
|
};
|
||||||
|
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 GetUserInfos(
|
||||||
|
token: token,
|
||||||
|
request: requestString
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<XOpenActionUserInfoDto>> GetUserInfos(
|
||||||
|
XOpenActionInnerDto dto
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
return await GetUserInfos(
|
||||||
|
token: dto.Token,
|
||||||
|
request: dto.Payload
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<XOpenActionUserInfoDto>> GetUserInfos(
|
||||||
|
string token,
|
||||||
|
string request
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Args ...
|
||||||
|
validationProvider.NotEmpty(token);
|
||||||
|
validationProvider.NotEmpty(request);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve and Validate Response ...
|
||||||
|
var response = await OpenGet(
|
||||||
|
token: token,
|
||||||
|
actionRequest: request
|
||||||
|
);
|
||||||
|
if (response.IsNull() ||
|
||||||
|
response.Token.IsNullOrEmpty() ||
|
||||||
|
response.Payload.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Now we Have to Converts Repose Payload to Result Model ...
|
||||||
|
// Note that the respose Model's payload here is Decrypted and
|
||||||
|
// actually is Json Representation of Result Model ...
|
||||||
|
var result = response.Payload.FromJSON<IEnumerable<XOpenActionUserInfoDto>>();
|
||||||
|
if (result.IsNull())
|
||||||
|
{
|
||||||
|
XException.ActionFailed.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user