I am using developer portal and i want to delegate the signin process from other application. i have this code for signin but it is giving unauthorize error. i have taken this from sample and now trying to login to developer portal with this.
I have checked azure api documentation its the same api there still ""users/" + User.Identity.GetName() + "/token?" return unauthorize
//create user in APIM as well
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(ApimRestHost);
client.DefaultRequestHeaders.Add("Authorization", ApimRestAuthHeader());
var ApimUser = new
{
keyType = "primary",
expiry = ApimRestExpiry
};
var ApimUserJson = JsonSerializer.Serialize(ApimUser);
HttpResponseMessage response = await client.PostAsync("users/" + User.Identity.GetName() + "/token?api-version=2023-03-01-preview", this.GetContent(ApimUserJson));
if (response.IsSuccessStatusCode)
{
//We got an SSO token - redirect
HttpContent receiveStream = response.Content;
var SsoUrlJson = await receiveStream.ReadAsStringAsync();
var su = JsonSerializer.Deserialize<SsoUrl>(SsoUrlJson);
//We need to encode the primary key before passing it to the sso url.
string url = string.Format("{0}/signin-sso?token={1}", developerPortalUrl, HttpUtility.UrlEncode(su.value));
return Redirect(url);
}
else
{
@ViewBag.Message = "APIM REST Connection Error: " + response.StatusCode;
return View();
}
}
// token for headers
public string ApimRestAuthHeader()
{
using (var encoder = new HMACSHA512(Encoding.UTF8.GetBytes(ApimRestPK)))
{
var dataToSign = ApimRestId + "\n" + ApimRestExpiry.ToString("O", CultureInfo.InvariantCulture);
var hash = encoder.ComputeHash(Encoding.UTF8.GetBytes(dataToSign));
var signature = Convert.ToBase64String(hash);
var encodedToken = string.Format("SharedAccessSignature uid={0}&ex={1:o}&sn={2}", ApimRestId, ApimRestExpiry, signature);
return encodedToken;
}
}
i have tried multiple token i have delegation token now what should i change for authorization of that api