asp.net-mvc


identityServer - AuthenticationTicket.Identitdoes.FindFirst not find claims


I am attempting to write a single sign authentication/authorization MVC web application that authenticates a user from client application(s) using OWIN and IdentityServer3 but AuthenticationTicket.Identitdoes.FindFirst not find claims or my identityServer does not send claims
identityServer-startup
app.Map("/identity", idsrvApp =>
{
var idServerServiceFactory = new IdentityServerServiceFactory()
.UseInMemoryUsers(Users.Get())
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get());
var options = new IdentityServerOptions
{
Factory = idServerServiceFactory,
SiteName = "identity",
IssuerUri = "https://iauec/identity",
PublicOrigin = "https://localhost:44362/",
SigningCertificate = LoadCertificate(),
EnableWelcomePage = true,
AuthenticationOptions =
{
EnablePostSignOutAutoRedirect=true,
PostSignOutAutoRedirectDelay=5,
EnableSignOutPrompt=true,
}
};
idsrvApp.UseIdentityServer(options);
});
identityServer-Client
Client
{
ClientId = "clientidtest1",
ClientName = "Client Name test1",
Flow = Flows.Hybrid,
AllowAccessToAllScopes = true,
ClientSecrets = new List<Secret>
{
new Secret("clientidtest1".Sha256())
},
//redirect = URI of the MVC application
RedirectUris = new List<string>()
{
"http://localhost:4865/"
}
}
identityServer-User
new InMemoryUser
{
Username = "Hossein",
Password = "123456",
Subject = "147",
Claims = new []
{
new Claim(Constants.ClaimTypes.GivenName,"Hossein"),
new Claim(Constants.ClaimTypes.FamilyName,"Alizadeh"),
new Claim(Constants.ClaimTypes.Role,"Admin")
}
identityServer-Scope
public static IEnumerable<Scope> Get()
{
return new List<Scope>
{
new Scope
{
Name = "scope1",
DisplayName = "scope 1",
Description = "Description.....",
Type = ScopeType.Identity,
Claims = new List<ScopeClaim>()
{
new ScopeClaim(Constants.ClaimTypes.Role)
}
},
StandardScopes.OpenId,
StandardScopes.Profile,
StandardScopes.Roles
};
}
MVC-Client-Startup
public void Configuration(IAppBuilder app)
{
JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();
AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject;
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = "clientidtest1",
Authority = "https://localhost:44362/identity",
RedirectUri = "http://localhost:4865/",
UseTokenLifetime = false,
SignInAsAuthenticationType = "Cookies",
ResponseType = "code id_token",
Scope = "openid profile roles",
ClientSecret = "clientidtest1",
//Notifications = new OpenIdConnectAuthenticationNotifications()
Notifications = new OpenIdConnectAuthenticationNotifications
{
#region Toke validate
SecurityTokenValidated = n =>
{
var id = n.AuthenticationTicket.Identity;
// we want to keep first name, last name, subject and roles
var givenName = n.AuthenticationTicket
.Identity.FindFirst(JwtClaimTypes.GivenName);
var familyName = id.FindFirst(Constants.ClaimTypes.FamilyName);
var sub = id.FindFirst(Constants.ClaimTypes.Subject);
var roles = id.FindAll(Constants.ClaimTypes.Role);
// create new identity and set name and role claim type
var nid = new ClaimsIdentity(
id.AuthenticationType,
Constants.ClaimTypes.GivenName,
Constants.ClaimTypes.Role);
nid.AddClaim(givenName);
nid.AddClaim(familyName);
nid.AddClaim(sub);
nid.AddClaims(roles);
// add some other app specific claim
nid.AddClaim(new Claim("app_specific", "some data"));
n.AuthenticationTicket = new AuthenticationTicket(
nid,
n.AuthenticationTicket.Properties);
return Task.FromResult(0);
},
#endregion
}
});
}

Related Links

MVC retrieve value dynamically from resource file
ASP.Net Web API: Regarding web api action calling url or end point url
How to render database row as html header in mvc 4?
Why private static variable becomes null at some point and what can I do to resolve?
Simple Injector and Cookies
how to use resolve url in mvc controller
When using asp.net-mvc, What is the best way to update multple page sections with one HTML.Action() method
Why do we need to avoid using IQueryable directly in an ASP.NET MVC view?
google authentication return access denied after authorization page via owin
ReactJs.Net, Gulp, Babel, Browserify MVC
Changing partial views in the same view based on menu
What are good naming conventions for an ASP.net solution
MVC File upload Where to put code
Passing form input from view to controller
Federated authentication from ASP.NET MVC to SharePoint
Assigning PK from another datasource as a PK in new application / model

Categories

HOME
asp.net-identity
jsp
performance-testing
tcl
parse.com
design
asana
prometheus
format
delphi-xe7
struts2-jquery
android-vision
overloading
wavelet
session-cookies
orientdb-2.1
html-email
zap
h.264
sfsafariviewcontroller
nested-set-model
jcrop
esri
unsigned-integer
listbox
jtable
pdfa
buffer-overflow
kprobe
mobilefirst-bluemix
tweenmax
detach
executorservice
chamilo-lms
p4-lang
zipline
caldroid
spring-saml
windows-scripting
atlassian-bitbucketserver
protobuf-3
google-slides
easy-digital-downloads
invalidate
dependency-management
move
http-status-code-500
mspgcc
flying-saucer
jvm-arguments
autogen
jcuda
breach-attack
kie-workbench
django-errors
mailcore2
ispconfig
android-chips
flattr
building
sizeof
telecommunication
securesocial
uploadify
groupbox
sqlj
readline
openocd
ubiquity
base-conversion
maven-cargo
dhc
cvs2git
opensc
catalina.out
cpp-netlib
datacontractserializer
django-supervisor
dataformat
disabled-input
sshj
appstore-sandbox
execcommand
gora
repeating
rte
jquery-data
progressdialog
dependency-walker
cloud-hosting
msxsl
ondraw
exact-synergy-enterprise
orthographic
fogbugz-on-demand

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App