-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
For those who would like to do Home realm discovery using Azure Function, the run.csx provided in the project is based on c# script, if you wish to do it in C#, below is the equivalent code.
`` public static class HRD_Detect
{
[FunctionName("GetIdProvider")]
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("IdP selection received a request.");
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic reqdata = JsonConvert.DeserializeObject(requestBody);
log.LogInformation($"request : {reqdata}");
if (reqdata.emailAddress == null)
{
log.LogInformation($"Empty request, email was null");
return new OkResult();
}
var email = ((string)reqdata.emailAddress).ToLower();
log.LogInformation($"email: {email}");
char splitter = '@';
string[] splitEmail = email.Split(splitter);
var emailSuffix = splitEmail[1];
if (email == "[email protected]")
{
log.LogInformation($"Identity Provider: aad");
return new OkObjectResult(
new ResponseContent
{
version = "1.0.0",
status = (int)HttpStatusCode.OK,
userMessage = $"Your account is a generic Azure AD account.",
idp = "aad",
signInName = email
});
}
//For B2C local accounts
if (email == "[email protected]")
{
log.LogInformation($"Identity Provider: local");
return new OkObjectResult(
new ResponseContent
{
version = "1.0.0",
status = (int)HttpStatusCode.OK,
userMessage = $"Your account seems to be a local account.",
idp = "local",
signInName = email
});
}
//For Contoso AAD accounts
if (emailSuffix == "contoso.com")
{
log.LogInformation($"Identity Provider: contoso");
return new OkObjectResult(
new ResponseContent
{
version = "1.0.0",
status = (int)HttpStatusCode.OK,
userMessage = $"Your account belongs to the contoso Identity Provider",
idp = "contoso",
signInName = email
});
}
else
{
log.LogInformation($"Identity Provider: none");
return new OkObjectResult(
new BlankContent
{
status = (int)HttpStatusCode.OK,
signInName = email
});
}
//return new OkResult();
}
}
//Default responses where there is no match
public class BlankContent
{
public int status { get; set; }
public string signInName { get; set; }
}
//For responses where there is an IdP matching
public class ResponseContent
{
public string version { get; set; }
public int status { get; set; }
public string userMessage { get; set; }
public string idp { get; set; }
public string signInName { get; set; }
}
}
``
Metadata
Metadata
Assignees
Labels
No labels