本文整理汇总了C#中IUserAuthRepository.GetUserAuth方法的典型用法代码示例。如果您正苦于以下问题:C# IUserAuthRepository.GetUserAuth方法的具体用法?C# IUserAuthRepository.GetUserAuth怎么用?C# IUserAuthRepository.GetUserAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserAuthRepository
的用法示例。
在下文中一共展示了IUserAuthRepository.GetUserAuth方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasAllRoles
public bool HasAllRoles(IHttpRequest req, IAuthSession session, IUserAuthRepository userAuthRepo=null)
{
if (HasAllRoles(session)) return true;
if (userAuthRepo == null)
userAuthRepo = req.TryResolve<IUserAuthRepository>();
if (userAuthRepo == null) return false;
var userAuth = userAuthRepo.GetUserAuth(session, null);
session.UpdateSession(userAuth);
if (HasAllRoles(session))
{
req.SaveSession(session);
return true;
}
return false;
}
示例2: Does_persist_FacebookOAuth
public void Does_persist_FacebookOAuth(IUserAuthRepository userAuthRepository)
{
InitTest(userAuthRepository);
var serviceTokens = MockAuthHttpGateway.Tokens = facebookGatewayTokens;
var oAuthUserSession = requestContext.ReloadSession();
var authInfo = new Dictionary<string, string> { };
var facebookAuth = GetFacebookAuthProvider();
facebookAuth.OnAuthenticated(service, oAuthUserSession, facebookAuthTokens, authInfo);
oAuthUserSession = requestContext.ReloadSession();
Assert.That(oAuthUserSession.FacebookUserId, Is.EqualTo(serviceTokens.UserId));
Assert.That(oAuthUserSession.UserAuthId, Is.Not.Null);
var userAuth = userAuthRepository.GetUserAuth(oAuthUserSession.UserAuthId);
Assert.That(userAuth.Id.ToString(CultureInfo.InvariantCulture), Is.EqualTo(oAuthUserSession.UserAuthId));
Assert.That(userAuth.DisplayName, Is.EqualTo(serviceTokens.DisplayName));
Assert.That(userAuth.FirstName, Is.EqualTo(serviceTokens.FirstName));
Assert.That(userAuth.LastName, Is.EqualTo(serviceTokens.LastName));
Assert.That(userAuth.PrimaryEmail, Is.EqualTo(serviceTokens.Email));
var authProviders = userAuthRepository.GetUserAuthDetails(oAuthUserSession.UserAuthId);
Assert.That(authProviders.Count, Is.EqualTo(1));
var authProvider = authProviders[0];
Assert.That(authProvider.UserAuthId, Is.EqualTo(userAuth.Id));
Assert.That(authProvider.DisplayName, Is.EqualTo(serviceTokens.DisplayName));
Assert.That(authProvider.FirstName, Is.EqualTo(serviceTokens.FirstName));
Assert.That(authProvider.LastName, Is.EqualTo(serviceTokens.LastName));
Assert.That(authProvider.Email, Is.EqualTo(serviceTokens.Email));
Assert.That(authProvider.RequestToken, Is.Null);
Assert.That(authProvider.RequestTokenSecret, Is.Null);
Assert.That(authProvider.AccessToken, Is.Null);
Assert.That(authProvider.AccessTokenSecret, Is.EqualTo(facebookAuthTokens.AccessTokenSecret));
Console.WriteLine(authProviders.Dump());
}
示例3: Can_login_with_user_created_CreateUserAuth
public void Can_login_with_user_created_CreateUserAuth(IUserAuthRepository userAuthRepository)
{
InitTest(userAuthRepository);
var registrationService = GetRegistrationService(userAuthRepository);
var responseObj = registrationService.Post(registrationDto);
var httpResult = responseObj as IHttpResult;
if (httpResult != null)
{
Assert.Fail("HttpResult found: " + httpResult.Dump());
}
var response = (RegistrationResponse)responseObj;
Assert.That(response.UserId, Is.Not.Null);
var userAuth = userAuthRepository.GetUserAuth(response.UserId);
AssertEqual(userAuth, registrationDto);
userAuth = userAuthRepository.GetUserAuthByUserName(registrationDto.UserName);
AssertEqual(userAuth, registrationDto);
userAuth = userAuthRepository.GetUserAuthByUserName(registrationDto.Email);
AssertEqual(userAuth, registrationDto);
UserAuth userId;
var success = userAuthRepository.TryAuthenticate(registrationDto.UserName, registrationDto.Password, out userId);
Assert.That(success, Is.True);
Assert.That(userId, Is.Not.Null);
success = userAuthRepository.TryAuthenticate(registrationDto.Email, registrationDto.Password, out userId);
Assert.That(success, Is.True);
Assert.That(userId, Is.Not.Null);
success = userAuthRepository.TryAuthenticate(registrationDto.UserName, "Bad Password", out userId);
Assert.That(success, Is.False);
Assert.That(userId, Is.Null);
}
示例4: Does_persist_TwitterOAuth
public void Does_persist_TwitterOAuth(IUserAuthRepository userAuthRepository)
{
InitTest(userAuthRepository);
MockAuthHttpGateway.Tokens = twitterGatewayTokens;
var authInfo = new Dictionary<string, string> {
{"user_id", "133371690876022785"},
{"screen_name", "demisbellot"},
};
var oAuthUserSession = requestContext.ReloadSession();
var twitterAuth = GetTwitterAuthProvider();
twitterAuth.OnAuthenticated(service, oAuthUserSession, twitterAuthTokens, authInfo);
oAuthUserSession = requestContext.ReloadSession();
Assert.That(oAuthUserSession.UserAuthId, Is.Not.Null);
var userAuth = userAuthRepository.GetUserAuth(oAuthUserSession.UserAuthId);
Assert.That(userAuth.Id.ToString(CultureInfo.InvariantCulture), Is.EqualTo(oAuthUserSession.UserAuthId));
Assert.That(userAuth.DisplayName, Is.EqualTo("Demis Bellot TW"));
var authProviders = userAuthRepository.GetUserAuthDetails(oAuthUserSession.UserAuthId);
Assert.That(authProviders.Count, Is.EqualTo(1));
var authProvider = authProviders[0];
Assert.That(authProvider.UserAuthId, Is.EqualTo(userAuth.Id));
Assert.That(authProvider.DisplayName, Is.EqualTo("Demis Bellot TW"));
Assert.That(authProvider.FirstName, Is.Null);
Assert.That(authProvider.LastName, Is.Null);
Assert.That(authProvider.RequestToken, Is.EqualTo(twitterAuthTokens.RequestToken));
Assert.That(authProvider.RequestTokenSecret, Is.EqualTo(twitterAuthTokens.RequestTokenSecret));
Console.WriteLine(authProviders.Dump());
}
示例5: Logging_in_pulls_all_AuthInfo_from_repo_after_logging_in_all_AuthProviders
public void Logging_in_pulls_all_AuthInfo_from_repo_after_logging_in_all_AuthProviders(IUserAuthRepository userAuthRepository)
{
InitTest(userAuthRepository);
var oAuthUserSession = requestContext.ReloadSession();
//Facebook
LoginWithFacebook(oAuthUserSession);
//Twitter
MockAuthHttpGateway.Tokens = twitterGatewayTokens;
var authInfo = new Dictionary<string, string> {
{"user_id", "133371690876022785"},
{"screen_name", "demisbellot"},
};
var twitterAuth = GetTwitterAuthProvider();
twitterAuth.OnAuthenticated(service, oAuthUserSession, twitterAuthTokens, authInfo);
Console.WriteLine("UserId: " + oAuthUserSession.UserAuthId);
//Register
var registrationService = GetRegistrationService(userAuthRepository, oAuthUserSession, requestContext);
var responseObj = registrationService.Post(RegisterDto);
Assert.That(responseObj as IHttpError, Is.Null, responseObj.ToString());
Console.WriteLine("UserId: " + oAuthUserSession.UserAuthId);
var credentialsAuth = GetCredentialsAuthConfig();
var loginResponse = credentialsAuth.Authenticate(service, oAuthUserSession,
new Authenticate
{
provider = CredentialsAuthProvider.Name,
UserName = RegisterDto.UserName,
Password = RegisterDto.Password,
});
loginResponse.PrintDump();
oAuthUserSession = requestContext.ReloadSession();
Assert.That(oAuthUserSession.TwitterUserId, Is.EqualTo(authInfo["user_id"]));
Assert.That(oAuthUserSession.TwitterScreenName, Is.EqualTo(authInfo["screen_name"]));
var userAuth = userAuthRepository.GetUserAuth(oAuthUserSession.UserAuthId);
Assert.That(userAuth.Id.ToString(CultureInfo.InvariantCulture), Is.EqualTo(oAuthUserSession.UserAuthId));
Assert.That(userAuth.DisplayName, Is.EqualTo(RegisterDto.DisplayName));
Assert.That(userAuth.FirstName, Is.EqualTo(RegisterDto.FirstName));
Assert.That(userAuth.LastName, Is.EqualTo(RegisterDto.LastName));
Assert.That(userAuth.Email, Is.EqualTo(RegisterDto.Email));
Console.WriteLine(oAuthUserSession.Dump());
Assert.That(oAuthUserSession.ProviderOAuthAccess.Count, Is.EqualTo(2));
Assert.That(oAuthUserSession.IsAuthenticated, Is.True);
var authProviders = userAuthRepository.GetUserAuthDetails(oAuthUserSession.UserAuthId);
Assert.That(authProviders.Count, Is.EqualTo(2));
Console.WriteLine(userAuth.Dump());
Console.WriteLine(authProviders.Dump());
}
示例6: Does_merge_FacebookOAuth_TwitterOAuth
public void Does_merge_FacebookOAuth_TwitterOAuth(IUserAuthRepository userAuthRepository)
{
InitTest(userAuthRepository);
var serviceTokensFb = MockAuthHttpGateway.Tokens = facebookGatewayTokens;
var oAuthUserSession = requestContext.ReloadSession();
var facebookAuth = GetFacebookAuthProvider();
facebookAuth.OnAuthenticated(service, oAuthUserSession, facebookAuthTokens, new Dictionary<string, string>());
oAuthUserSession = requestContext.ReloadSession();
var serviceTokensTw = MockAuthHttpGateway.Tokens = twitterGatewayTokens;
var authInfo = new Dictionary<string, string> {
{"user_id", "133371690876022785"},
{"screen_name", "demisbellot"},
};
var twitterAuth = GetTwitterAuthProvider();
twitterAuth.OnAuthenticated(service, oAuthUserSession, twitterAuthTokens, authInfo);
oAuthUserSession = requestContext.ReloadSession();
Assert.That(oAuthUserSession.TwitterUserId, Is.EqualTo(authInfo["user_id"]));
Assert.That(oAuthUserSession.TwitterScreenName, Is.EqualTo(authInfo["screen_name"]));
var userAuth = userAuthRepository.GetUserAuth(oAuthUserSession.UserAuthId);
Assert.That(userAuth.Id.ToString(CultureInfo.InvariantCulture), Is.EqualTo(oAuthUserSession.UserAuthId));
Assert.That(userAuth.DisplayName, Is.EqualTo(serviceTokensFb.DisplayName));
Assert.That(userAuth.PrimaryEmail, Is.EqualTo(serviceTokensFb.Email));
Assert.That(userAuth.FirstName, Is.EqualTo(serviceTokensFb.FirstName));
Assert.That(userAuth.LastName, Is.EqualTo(serviceTokensFb.LastName));
var authProviders = userAuthRepository.GetUserAuthDetails(oAuthUserSession.UserAuthId);
Assert.That(authProviders.Count, Is.EqualTo(2));
Console.WriteLine(userAuth.Dump());
Console.WriteLine(authProviders.Dump());
}
示例7: Can_login_with_user_created_CreateUserAuth
public void Can_login_with_user_created_CreateUserAuth(IUserAuthRepository userAuthRepository)
{
((IClearable)userAuthRepository).Clear();
var request = new Registration {
UserName = "UserName",
Password = "[email protected]",
Email = "[email protected]",
DisplayName = "DisplayName",
FirstName = "FirstName",
LastName = "LastName",
};
var loginService = new RegistrationService {
UserAuthRepo = userAuthRepository,
RegistrationValidator = new RegistrationValidator { UserAuthRepo = RegistrationServiceTests.GetStubRepo() },
};
var responseObj = loginService.Post(request);
var httpResult = responseObj as IHttpResult;
if (httpResult != null)
{
Assert.Fail("HttpResult found: " + httpResult.Dump());
}
var response = (RegistrationResponse)responseObj;
Assert.That(response.UserId, Is.Not.Null);
var userAuth = userAuthRepository.GetUserAuth(response.UserId);
AssertEqual(userAuth, request);
userAuth = userAuthRepository.GetUserAuthByUserName(request.UserName);
AssertEqual(userAuth, request);
userAuth = userAuthRepository.GetUserAuthByUserName(request.Email);
AssertEqual(userAuth, request);
string userId;
var success = userAuthRepository.TryAuthenticate(request.UserName, request.Password, out userId);
Assert.That(success, Is.True);
Assert.That(userId, Is.Not.Null);
success = userAuthRepository.TryAuthenticate(request.Email, request.Password, out userId);
Assert.That(success, Is.True);
Assert.That(userId, Is.Not.Null);
success = userAuthRepository.TryAuthenticate(request.UserName, "Bad Password", out userId);
Assert.That(success, Is.False);
Assert.That(userId, Is.Null);
}
示例8: Does_persist_TwitterOAuth
public void Does_persist_TwitterOAuth(IUserAuthRepository userAuthRepository)
{
((IClearable)userAuthRepository).Clear();
var mockService = new Mock<IServiceBase>();
mockService.Expect(x => x.TryResolve<IUserAuthRepository>())
.Returns(userAuthRepository);
var service = mockService.Object;
MockAuthHttpGateway.Tokens = new OAuthTokens { DisplayName = "Demis Bellot TW" };
var twitterTokens = new OAuthTokens {
Provider = TwitterAuthConfig.Name,
RequestToken = "JGz2CcwqgB1GR5e0EmGFxzyxGTw2rwEFFcC8a9o7g",
RequestTokenSecret = "qkCdURJ2R10bMieVQZZad7iSwWkPYJmtBYzPoM9q0",
UserId = "133371690876022785",
};
var authInfo = new Dictionary<string, string> {
{"user_id", "133371690876022785"},
{"screen_name", "demisbellot"},
};
var oAuthUserSession = GetSession();
oAuthUserSession.OnAuthenticated(service, twitterTokens, authInfo);
Assert.That(oAuthUserSession.UserAuthId, Is.Not.Null);
var userAuth = userAuthRepository.GetUserAuth(oAuthUserSession.UserAuthId);
Assert.That(userAuth.Id.ToString(), Is.EqualTo(oAuthUserSession.UserAuthId));
Assert.That(userAuth.DisplayName, Is.EqualTo("Demis Bellot TW"));
var authProviders = userAuthRepository.GetUserOAuthProviders(oAuthUserSession.UserAuthId);
Assert.That(authProviders.Count, Is.EqualTo(1));
var authProvider = authProviders[0];
Assert.That(authProvider.UserAuthId, Is.EqualTo(userAuth.Id));
Assert.That(authProvider.DisplayName, Is.EqualTo("Demis Bellot TW"));
Assert.That(authProvider.FirstName, Is.Null);
Assert.That(authProvider.LastName, Is.Null);
Assert.That(authProvider.RequestToken, Is.EqualTo(twitterTokens.RequestToken));
Assert.That(authProvider.RequestTokenSecret, Is.EqualTo(twitterTokens.RequestTokenSecret));
Console.WriteLine(authProviders.Dump());
}
示例9: Does_persist_FacebookOAuth
public void Does_persist_FacebookOAuth(IUserAuthRepository userAuthRepository)
{
((IClearable)userAuthRepository).Clear();
var mockService = new Mock<IServiceBase>();
mockService.Expect(x => x.TryResolve<IUserAuthRepository>())
.Returns(userAuthRepository);
var serviceTokens = MockAuthHttpGateway.Tokens = new OAuthTokens {
UserId = "623501766",
DisplayName = "Demis Bellot FB",
FirstName = "Demis",
LastName = "Bellot",
Email = "[email protected]",
};
var service = mockService.Object;
var facebookTokens = new OAuthTokens {
Provider = FacebookAuthConfig.Name,
AccessTokenSecret = "AAADPaOoR848BAMkQIZCRIKnVWZAvcKWqo7Ibvec8ebV9vJrfZAz8qVupdu5EbjFzmMmbwUFDbcNDea9H6rOn5SVn8es7KYZD",
};
var authInfo = new Dictionary<string, string> { };
var oAuthUserSession = GetSession();
oAuthUserSession.OnAuthenticated(service, facebookTokens, authInfo);
Assert.That(oAuthUserSession.FacebookUserId, Is.EqualTo(serviceTokens.UserId));
Assert.That(oAuthUserSession.UserAuthId, Is.Not.Null);
var userAuth = userAuthRepository.GetUserAuth(oAuthUserSession.UserAuthId);
Assert.That(userAuth.Id.ToString(), Is.EqualTo(oAuthUserSession.UserAuthId));
Assert.That(userAuth.DisplayName, Is.EqualTo(serviceTokens.DisplayName));
Assert.That(userAuth.FirstName, Is.EqualTo(serviceTokens.FirstName));
Assert.That(userAuth.LastName, Is.EqualTo(serviceTokens.LastName));
Assert.That(userAuth.Email, Is.EqualTo(serviceTokens.Email));
var authProviders = userAuthRepository.GetUserOAuthProviders(oAuthUserSession.UserAuthId);
Assert.That(authProviders.Count, Is.EqualTo(1));
var authProvider = authProviders[0];
Assert.That(authProvider.UserAuthId, Is.EqualTo(userAuth.Id));
Assert.That(authProvider.DisplayName, Is.EqualTo(serviceTokens.DisplayName));
Assert.That(authProvider.FirstName, Is.EqualTo(serviceTokens.FirstName));
Assert.That(authProvider.LastName, Is.EqualTo(serviceTokens.LastName));
Assert.That(authProvider.Email, Is.EqualTo(serviceTokens.Email));
Assert.That(authProvider.RequestToken, Is.Null);
Assert.That(authProvider.RequestTokenSecret, Is.Null);
Assert.That(authProvider.AccessToken, Is.Null);
Assert.That(authProvider.AccessTokenSecret, Is.EqualTo(facebookTokens.AccessTokenSecret));
Console.WriteLine(authProviders.Dump());
}
示例10: Does_merge_FacebookOAuth_TwitterOAuth
public void Does_merge_FacebookOAuth_TwitterOAuth(IUserAuthRepository userAuthRepository)
{
((IClearable)userAuthRepository).Clear();
var mockService = new Mock<IServiceBase>();
mockService.Expect(x => x.TryResolve<IUserAuthRepository>())
.Returns(userAuthRepository);
var service = mockService.Object;
var serviceTokensFb = MockAuthHttpGateway.Tokens = new OAuthTokens {
UserId = "623501766",
DisplayName = "Demis Bellot FB",
FirstName = "Demis",
LastName = "Bellot",
Email = "[email protected]",
};
var facebookTokens = new OAuthTokens {
Provider = FacebookAuthConfig.Name,
AccessTokenSecret = "AAADDDCCCoR848BAMkQIZCRIKnVWZAvcKWqo7Ibvec8ebV9vJrfZAz8qVupdu5EbjFzmMmbwUFDbcNDea9H6rOn5SVn8es7KYZD",
};
var oAuthUserSession = GetSession();
oAuthUserSession.OnAuthenticated(service, facebookTokens, new Dictionary<string, string>());
var serviceTokensTw = MockAuthHttpGateway.Tokens = new OAuthTokens { DisplayName = "Demis Bellot TW" };
var twitterTokens = new OAuthTokens {
Provider = TwitterAuthConfig.Name,
RequestToken = "JGGZZ22CCqgB1GR5e0EmGFxzyxGTw2rwEFFcC8a9o7g",
RequestTokenSecret = "qKKCCUUJ2R10bMieVQZZad7iSwWkPYJmtBYzPoM9q0",
UserId = "133371690876022785",
};
var authInfo = new Dictionary<string, string> {
{"user_id", "133371690876022785"},
{"screen_name", "demisbellot"},
};
oAuthUserSession.OnAuthenticated(service, twitterTokens, authInfo);
Assert.That(oAuthUserSession.TwitterUserId, Is.EqualTo(authInfo["user_id"]));
Assert.That(oAuthUserSession.TwitterScreenName, Is.EqualTo(authInfo["screen_name"]));
var userAuth = userAuthRepository.GetUserAuth(oAuthUserSession.UserAuthId);
Assert.That(userAuth.Id.ToString(), Is.EqualTo(oAuthUserSession.UserAuthId));
Assert.That(userAuth.DisplayName, Is.EqualTo(serviceTokensTw.DisplayName));
Assert.That(userAuth.FirstName, Is.EqualTo(serviceTokensFb.FirstName));
Assert.That(userAuth.LastName, Is.EqualTo(serviceTokensFb.LastName));
Assert.That(userAuth.Email, Is.EqualTo(serviceTokensFb.Email));
var authProviders = userAuthRepository.GetUserOAuthProviders(oAuthUserSession.UserAuthId);
Assert.That(authProviders.Count, Is.EqualTo(2));
Console.WriteLine(userAuth.Dump());
Console.WriteLine(authProviders.Dump());
}
示例11: UpdateFromUserAuthRepo
public static void UpdateFromUserAuthRepo(this IAuthSession session, IHttpRequest req, IUserAuthRepository userAuthRepo = null)
{
if (userAuthRepo == null)
userAuthRepo = req.TryResolve<IUserAuthRepository>();
if (userAuthRepo == null) return;
var userAuth = userAuthRepo.GetUserAuth(session, null);
session.UpdateSession(userAuth);
}