本文整理汇总了C#中IAuthTokens类的典型用法代码示例。如果您正苦于以下问题:C# IAuthTokens类的具体用法?C# IAuthTokens怎么用?C# IAuthTokens使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAuthTokens类属于命名空间,在下文中一共展示了IAuthTokens类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadUserAuth
public void LoadUserAuth(IAuthSession session, IAuthTokens tokens)
{
session.ThrowIfNull("session");
var userAuth = GetUserAuth(session, tokens);
LoadUserAuth(session, (UserAuth)userAuth);
}
示例2: GetUserAuth
public IUserAuth GetUserAuth(IAuthSession authSession, IAuthTokens tokens)
{
if (!string.IsNullOrEmpty(authSession.UserAuthId))
{
var userAuth = GetUserAuth(authSession.UserAuthId);
if (userAuth != null) return userAuth;
}
if (!string.IsNullOrEmpty(authSession.UserAuthName))
{
var userAuth = GetUserAuthByUserName(authSession.UserAuthName);
if (userAuth != null) return userAuth;
}
if (tokens == null || string.IsNullOrEmpty(tokens.Provider) || string.IsNullOrEmpty(tokens.UserId))
return null;
var oAuthProvider = Session.QueryOver<UserAuthDetails>()
.Where(x => x.Provider == tokens.Provider)
.And(x => x.UserId == tokens.UserId)
.SingleOrDefault();
if (oAuthProvider != null)
{
return Session.QueryOver<UserAuthPersistenceDto>()
.Where(x => x.Id == oAuthProvider.UserAuthId)
.SingleOrDefault();
}
return null;
}
示例3: SaveUserAuth
/// <summary>
/// Saves the Auth Tokens for this request. Called in OnAuthenticated().
/// Overrideable, the default behaviour is to call IUserAuthRepository.CreateOrMergeAuthSession().
/// </summary>
protected virtual void SaveUserAuth(IServiceBase authService, IAuthSession session, IAuthRepository authRepo, IAuthTokens tokens)
{
if (authRepo == null) return;
if (tokens != null)
{
session.UserAuthId = authRepo.CreateOrMergeAuthSession(session, tokens);
}
authRepo.LoadUserAuth(session, tokens);
foreach (var oAuthToken in session.ProviderOAuthAccess)
{
var authProvider = AuthenticateService.GetAuthProvider(oAuthToken.Provider);
if (authProvider == null) continue;
var userAuthProvider = authProvider as OAuthProvider;
if (userAuthProvider != null)
{
userAuthProvider.LoadUserOAuthProvider(session, oAuthToken);
}
}
authRepo.SaveUserAuth(session);
var httpRes = authService.Request.Response as IHttpResponse;
if (httpRes != null)
{
httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
}
OnSaveUserAuth(authService, session);
}
示例4: GetUserAuth
public IUserAuth GetUserAuth(IAuthSession authSession, IAuthTokens tokens)
{
//if (!authSession.UserAuthId.IsNullOrEmpty())
//{
// var userAuth = GetUserAuth(authSession.UserAuthId);
// if (userAuth != null)
// {
// return userAuth;
// }
//}
if (!authSession.UserAuthName.IsNullOrEmpty())
{
var userAuth = GetUserAuthByUserName(authSession.UserAuthName);
if (userAuth != null)
{
return userAuth;
}
}
if (tokens == null || tokens.Provider.IsNullOrEmpty() || tokens.UserId.IsNullOrEmpty())
{
return null;
}
return null;
}
示例5: AddProfileUrl
public virtual void AddProfileUrl(IAuthTokens tokens, Dictionary<string, string> authInfo)
{
if (tokens == null || authInfo == null)
return;
var items = tokens.Items ?? (tokens.Items = new Dictionary<string, string>());
if (items.ContainsKey(ProfileUrlKey))
return;
try
{
//Provide Fallback to retrieve avatar urls in-case built-in access fails
if (tokens.Provider == FacebookAuthProvider.Name)
{
items[ProfileUrlKey] = GetRedirectUrlIfAny(
$"http://avatars.io/facebook/{tokens.UserName}?size=medium");
}
else if (tokens.Provider == TwitterAuthProvider.Name)
{
items[ProfileUrlKey] = GetRedirectUrlIfAny(
$"http://avatars.io/twitter/{tokens.UserName}?size=medium");
}
if (!items.ContainsKey(ProfileUrlKey) && !tokens.Email.IsNullOrEmpty())
items[ProfileUrlKey] = tokens.Email.ToGravatarUrl(size: 64);
}
catch (Exception ex)
{
Log.Error("Error AddProfileUrl to: {0}>{1}".Fmt(tokens.Provider, tokens.UserName), ex);
}
}
示例6: AddAuthToken
public static void AddAuthToken(this IAuthSession session, IAuthTokens tokens)
{
if (session.ProviderOAuthAccess == null)
session.ProviderOAuthAccess = new List<IAuthTokens>();
session.ProviderOAuthAccess.Add(tokens);
}
示例7: GetUserAuth
public IUserAuth GetUserAuth(IAuthSession authSession, IAuthTokens tokens)
{
if (!string.IsNullOrEmpty(authSession.UserAuthId))
{
var userAuth = GetUserAuth(authSession.UserAuthId);
if (userAuth != null) return userAuth;
}
if (!string.IsNullOrEmpty(authSession.UserAuthName))
{
var userAuth = GetUserAuthByUserName(authSession.UserAuthName);
if (userAuth != null) return userAuth;
}
if (tokens == null || string.IsNullOrEmpty(tokens.Provider) || string.IsNullOrEmpty(tokens.UserId))
return null;
var nhSession = GetCurrentSessionFn(sessionFactory);
var oAuthProvider = nhSession.QueryOver<UserAuthDetailsNHibernate>()
.Where(x => x.Provider == tokens.Provider)
.And(x => x.UserId == tokens.UserId)
.SingleOrDefault();
if (oAuthProvider != null)
{
return nhSession.QueryOver<UserAuthNHibernate>()
.Where(x => x.Id == oAuthProvider.UserAuthId)
.SingleOrDefault();
}
return null;
}
示例8: LoadUserAuth
public void LoadUserAuth(IAuthSession session, IAuthTokens tokens)
{
if (session == null)
throw new ArgumentNullException(nameof(session));
var userAuth = GetUserAuth(session, tokens);
LoadUserAuth(session, (UserAuth)userAuth);
}
示例9: OnAuthenticated
/// <summary>
/// The on-authenticated event handler.
/// </summary>
/// <param name="authService">The authentication service.</param>
/// <param name="session">The authentication session.</param>
/// <param name="tokens">The authentication tokens.</param>
/// <param name="authInfo">The authentication information.</param>
public override void OnAuthenticated(
IServiceBase authService,
IAuthSession session,
IAuthTokens tokens,
Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
}
示例10: OnAuthenticated
/// <summary>
/// Método que se ejecuta cuando se ha autenticado con éxito
/// </summary>
/// <param name="authService">Servicio que solicita la autenticación</param>
/// <param name="session">Información de sesión</param>
/// <param name="tokens">Tokets</param>
/// <param name="authInfo">Información de autenticación</param>
/// <returns></returns>
public override IHttpResult OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
{
session.FirstName = _fullName;
authService.SaveSession(session);
return null;
}
示例11: IsAuthorized
public override bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
{
if (request != null)
{
if (!LoginMatchesSession(session, request.UserName)) return false;
}
return tokens != null && !string.IsNullOrEmpty(tokens.AccessTokenSecret);
}
示例12: LoadUserOAuthProvider
public override void LoadUserOAuthProvider(IAuthSession authSession, IAuthTokens tokens)
{
var userSession = authSession as AuthUserSession;
if (userSession == null) return;
userSession.TwitterUserId = tokens.UserId ?? userSession.TwitterUserId;
userSession.TwitterScreenName = tokens.UserName ?? userSession.TwitterScreenName;
userSession.DisplayName = tokens.DisplayName ?? userSession.DisplayName;
}
示例13: IsAuthorized
public override bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
{
if (request != null) {
if (!LoginMatchesSession(session, request.UserName)) {
return false;
}
}
return !session.UserAuthName.IsNullOrEmpty();
}
示例14: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
//Populate all matching fields from this session to your own custom User table
var user = session.ConvertTo<User>();
user.Id = int.Parse(session.UserAuthId);
user.GravatarImageUrl64 = !session.Email.IsNullOrEmpty()
? CreateGravatarUrl(session.Email, 64)
: null;
foreach (var authToken in session.ProviderOAuthAccess)
{
if (authToken.Provider == FacebookAuthProvider.Name)
{
user.FacebookName = authToken.DisplayName;
user.FacebookFirstName = authToken.FirstName;
user.FacebookLastName = authToken.LastName;
user.FacebookEmail = authToken.Email;
}
else if (authToken.Provider == TwitterAuthProvider.Name)
{
user.TwitterName = user.DisplayName = authToken.UserName;
}
else if (authToken.Provider == GoogleOpenIdOAuthProvider.Name)
{
user.GoogleUserId = authToken.UserId;
user.GoogleFullName = authToken.FullName;
user.GoogleEmail = authToken.Email;
}
else if (authToken.Provider == YahooOpenIdOAuthProvider.Name)
{
user.YahooUserId = authToken.UserId;
user.YahooFullName = authToken.FullName;
user.YahooEmail = authToken.Email;
}
}
if (AppHost.AppConfig.AdminUserNames.Contains(session.UserAuthName)
&& !session.HasRole(RoleNames.Admin))
{
using (var assignRoles = authService.ResolveService<AssignRolesService>())
{
assignRoles.Post(new AssignRoles {
UserName = session.UserAuthName,
Roles = { RoleNames.Admin }
});
}
}
//Resolve the DbFactory from the IOC and persist the user info
using (var db = authService.TryResolve<IDbConnectionFactory>().Open())
db.Save(user);
}
示例15: IsAuthorized
public override bool IsAuthorized(IAuthSession session, IAuthTokens tokens, Authenticate request = null)
{
if (request != null)
{
//if (!LoginMatchesSession(session, request.UserName))
//{
// return false;
//}
throw new NotImplementedException();
}
return session != null && session.IsAuthenticated && !session.UserAuthName.IsNullOrEmpty();
}