Add script file and apply latest REST API definition (#1851)
- Meisterplan REST API now supports allocation entity to be resolved by key or name. Applied this change to the API definition file. - added script file so it is added to archive in ISV Studio. The script redirects the api calls to the correct region in case the connector is using OAuth authentication flow
This commit is contained in:
Родитель
3f38564f64
Коммит
82c593098f
|
@ -5051,19 +5051,21 @@
|
|||
"id": {
|
||||
"type": "string",
|
||||
"example": "UUID",
|
||||
"description": "The id of the entity to which this allocation is linked",
|
||||
"description": "The id of the entity to which this allocation is linked. Set type to RESOLVE_BY_KEY_OR_NAME to resolve resource keys or role names automatically instead.",
|
||||
"x-ms-summary": "Id"
|
||||
},
|
||||
"projectRole": {
|
||||
"type": "string",
|
||||
"example": "UUID",
|
||||
"description": "The role id to which this allocation is linked. This field is only valid in combination with the type \"RESOURCE\".",
|
||||
"description": "The role id to which this allocation is linked. This field is only valid in combination with the types RESOURCE or RESOLVE_BY_KEY_OR_NAME. If type is set to RESOLVE_BY_KEY_OR_NAME, projectRole is resolved by name.",
|
||||
"x-ms-summary": "Project Role"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "RESOURCE",
|
||||
"description": "Control how the value in the field id is interpreted. RESOURCE resolves resources by UUID. ROLE resolves roles by UUID. RESOLVE_BY_KEY_OR_NAME resolves either resources by resource key or roles by role name.",
|
||||
"enum": [
|
||||
"RESOLVE_BY_KEY_OR_NAME",
|
||||
"RESOURCE",
|
||||
"ROLE"
|
||||
],
|
||||
|
@ -5091,6 +5093,7 @@
|
|||
"type": "string",
|
||||
"description": "The entity type for this allocation",
|
||||
"enum": [
|
||||
"RESOLVE_BY_KEY_OR_NAME",
|
||||
"RESOURCE",
|
||||
"ROLE"
|
||||
],
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
public class Script : ScriptBase
|
||||
{
|
||||
public override async Task<HttpResponseMessage> ExecuteAsync()
|
||||
{
|
||||
this.UpdateBaseUri(GetBearerToken(this.Context.Request), this.Context.Request);
|
||||
HttpResponseMessage response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(false);
|
||||
return response;
|
||||
}
|
||||
|
||||
private void UpdateBaseUri(string bearerToken, HttpRequestMessage Request)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(bearerToken))
|
||||
{
|
||||
// Update base uri
|
||||
var baseUri = this.GetBaseUri(bearerToken);
|
||||
Request.RequestUri = new Uri(new Uri(baseUri), Request.RequestUri.PathAndQuery);
|
||||
}
|
||||
if (Request.Method.ToString().ToUpper() == "PATCH"){
|
||||
Request.Method = HttpMethod.Post;
|
||||
Request.Headers.Add( "X-HTTP-Method-Override","PATCH");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string GetBearerToken(HttpRequestMessage Request)
|
||||
{
|
||||
var bearerToken = string.Empty;
|
||||
IEnumerable<string> headerValues;
|
||||
if (Request.Headers.TryGetValues("Authorization", out headerValues))
|
||||
{
|
||||
bearerToken = headerValues.FirstOrDefault();
|
||||
}
|
||||
return bearerToken;
|
||||
}
|
||||
|
||||
private string GetBaseUri(string bearerToken)
|
||||
{
|
||||
var accessTokenClaimsBase64 = bearerToken.Substring(7).Split('.')[1];
|
||||
string token = accessTokenClaimsBase64.Replace('_', '/').Replace('-', '+');
|
||||
switch (token.Length % 4)
|
||||
{
|
||||
case 2: token += "=="; break;
|
||||
case 3: token += "="; break;
|
||||
}
|
||||
var encodedClaims = Encoding.UTF8.GetString(Convert.FromBase64String(token));
|
||||
var tokenClaimsJson = JObject.Parse(encodedClaims);
|
||||
var audience = (string)tokenClaimsJson["aud"];
|
||||
return "https://api." + audience;
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче