Created
August 9, 2013 21:30
-
-
Save phillee007/6197398 to your computer and use it in GitHub Desktop.
Thinktecture.IdentityModel configuration - basic + session token auth
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
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