Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Thinktecture.IdentityModel configuration - basic + session token auth
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var authConfig = new AuthenticationConfiguration
{
RequireSsl = false,
EnableSessionToken = true,
InheritHostClientIdentity = true,
ClaimsAuthenticationManager = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager
};
// setup authentication against membership
authConfig.AddBasicAuthentication(Verify);
config.MessageHandlers.Add(new AuthenticationHandler(authConfig));
}
public static bool Verify(string user, string pass)
{
var accountService = ServiceLocator.Current
.GetInstance<UserAccountService>();
var authSvc = ServiceLocator.Current
.GetInstance<AuthenticationService>();
BrockAllen.MembershipReboot.UserAccount account;
var isAuthenticated = accountService.AuthenticateWithUsernameOrEmail(user, pass, out account);
if(isAuthenticated){
authSvc.SignIn(account);
}
return isAuthenticated;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.