Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for identity bindings and samples
- Loading branch information
1 parent
f086912
commit 6e34b98
Showing
13 changed files
with
244 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"name": "req", | ||
"direction": "in", | ||
"methods": [ "get" ] | ||
}, | ||
{ | ||
"type": "http", | ||
"name": "$return", | ||
"direction": "out" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Linq; | ||
using System.Net; | ||
using System.Security.Claims; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
public static IActionResult Run(HttpRequest req, TraceWriter log, ClaimsPrincipal principal) | ||
{ | ||
log.Info("C# HTTP trigger function processed a request."); | ||
|
||
string[] identityStrings = principal.Identities.Select(GetIdentityString).ToArray(); | ||
|
||
return new OkObjectResult(string.Join(";", identityStrings)); | ||
} | ||
|
||
private static string GetIdentityString(ClaimsIdentity identity) | ||
{ | ||
var userIdClaim = identity.FindFirst(ClaimTypes.NameIdentifier); | ||
if (userIdClaim != null) | ||
{ | ||
// user identity | ||
var userNameClaim = identity.FindFirst(ClaimTypes.Name); | ||
return $"Identity: ({identity.AuthenticationType}, {userNameClaim.Value}, {userIdClaim.Value})"; | ||
} | ||
else | ||
{ | ||
// key based identity | ||
var authLevelClaim = identity.FindFirst("http://schemas.microsoft.com/2017/07/functions/claims/authlevel"); | ||
var keyIdClaim = identity.FindFirst("http://schemas.microsoft.com/2017/07/functions/claims/keyid"); | ||
return $"Identity: ({identity.AuthenticationType}, {authLevelClaim.Value}, {keyIdClaim.Value})"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"name": "req", | ||
"direction": "in", | ||
"methods": [ "get" ] | ||
}, | ||
{ | ||
"type": "http", | ||
"name": "$return", | ||
"direction": "out" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = function (context, req) { | ||
console.dir(context.bindingData.identities); | ||
var identityString = context.bindingData.identities.map(GetIdentityString).join(";"); | ||
|
||
var res = { | ||
status: 200, | ||
body: identityString, | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
}; | ||
|
||
context.done(null, res); | ||
}; | ||
|
||
function GetIdentityString(identity) { | ||
var nameIdentifierType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"; | ||
var userIdClaim = identity.claims.find(claim => claim.type === nameIdentifierType); | ||
if (userIdClaim) { | ||
// user claim | ||
var nameType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"; | ||
var userNameClaim = identity.claims.find(claim => claim.type === nameType); | ||
return `Identity: (${identity.authenticationType}, ${userNameClaim.value}, ${userIdClaim.value})`; | ||
} else { | ||
// key based identity | ||
var authLevelClaim = identity.claims.find(claim => claim.type === "http://schemas.microsoft.com/2017/07/functions/claims/authlevel"); | ||
var keyIdClaim = identity.claims.find(claim => claim.type === "http://schemas.microsoft.com/2017/07/functions/claims/keyid"); | ||
return `Identity: (${identity.authenticationType}, ${authLevelClaim.value}, ${keyIdClaim.value})`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters