本文整理汇总了C#中IOAuthTokens类的典型用法代码示例。如果您正苦于以下问题:C# IOAuthTokens类的具体用法?C# IOAuthTokens怎么用?C# IOAuthTokens使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IOAuthTokens类属于命名空间,在下文中一共展示了IOAuthTokens类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateOrMergeAuthSession
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens)
{
var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth();
return dbFactory.Exec(dbCmd => {
var oAuthProvider = dbCmd.FirstOrDefault<UserOAuthProvider>(
"Provider = {0} AND UserId = {1}", tokens.Provider, tokens.UserId);
if (oAuthProvider == null)
{
oAuthProvider = new UserOAuthProvider {
Provider = tokens.Provider,
UserId = tokens.UserId,
};
}
oAuthProvider.PopulateMissing(tokens);
userAuth.PopulateMissing(oAuthProvider);
dbCmd.Save(userAuth);
oAuthProvider.UserAuthId = userAuth.Id != default(int)
? userAuth.Id
: (int) dbCmd.GetLastInsertId();
dbCmd.Save(oAuthProvider);
return oAuthProvider.UserAuthId.ToString();
});
}
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:30,代码来源:OrmLiteAuthRepository.cs
示例2: LoadUserAuthInfo
/// <summary>Loads user authentication information.</summary>
///
/// <param name="userSession">The user session.</param>
/// <param name="tokens"> The tokens.</param>
/// <param name="authInfo"> Information describing the authentication.</param>
protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
if (authInfo.ContainsKey("user_id"))
tokens.UserId = authInfo.GetValueOrDefault("user_id");
if (authInfo.ContainsKey("screen_name"))
tokens.UserName = authInfo.GetValueOrDefault("screen_name");
try
{
if (tokens.UserId != null)
{
var json = AuthHttpGateway.DownloadTwitterUserInfo(tokens.UserId);
var objs = JsonObject.ParseArray(json);
if (objs.Count > 0)
{
var obj = objs[0];
tokens.DisplayName = obj.Get("name");
}
}
LoadUserOAuthProvider(userSession, tokens);
}
catch (Exception ex)
{
Log.Error("Could not retrieve twitter user info for '{0}'".Fmt(userSession.TwitterUserId), ex);
}
}
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:33,代码来源:TwitterAuthProvider.cs
示例3: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService,
IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
session.ReferrerUrl = "".MapHostAbsolutePath();
session.IsAuthenticated = true;
authService.SaveSession(session, new TimeSpan(7, 0, 0, 0));
}
开发者ID:TripThru,项目名称:Gateway,代码行数:7,代码来源:1396661660$TripThruPartnerGatewayHost.cs
示例4: CreateOrMergeAuthSession
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens)
{
using (var redis = factory.GetClient())
{
UserOAuthProvider oAuthProvider = null;
var oAuthProviderId = GetAuthProviderByUserId(redis, tokens.Provider, tokens.UserId);
if (!oAuthProviderId.IsNullOrEmpty())
oAuthProvider = redis.As<UserOAuthProvider>().GetById(oAuthProviderId);
var userAuth = GetUserAuth(redis, authSession, tokens)
?? new UserAuth { Id = redis.As<UserAuth>().GetNextSequence(), };
if (oAuthProvider == null)
{
oAuthProvider = new UserOAuthProvider {
Id = redis.As<UserOAuthProvider>().GetNextSequence(),
UserAuthId = userAuth.Id,
Provider = tokens.Provider,
UserId = tokens.UserId,
};
var idx = IndexProviderToUserIdHash(tokens.Provider);
redis.SetEntryInHash(idx, tokens.UserId, oAuthProvider.Id.ToString());
}
oAuthProvider.PopulateMissing(tokens);
userAuth.PopulateMissing(oAuthProvider);
redis.Store(userAuth);
redis.Store(oAuthProvider);
redis.AddItemToSet(IndexUserAuthAndProviderIdsSet(userAuth.Id), oAuthProvider.Id.ToString());
return userAuth.Id.ToString();
}
}
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:35,代码来源:RedisAuthRepository.cs
示例5: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService,
IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
session.ReferrerUrl = "/TripThru.TripThruGateway/";
session.IsAuthenticated = true;
authService.SaveSession(session, new TimeSpan(7, 0, 0, 0));
}
开发者ID:TripThru,项目名称:Gateway,代码行数:7,代码来源:1396661635$TripThruGatewayHost.cs
示例6: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
session.UserName = session.UserAuthName;
//Important: You need to save the session!
authService.SaveSession(session, SessionExpiry);
}
开发者ID:bholmes,项目名称:XamarinEvolve2013Project,代码行数:7,代码来源:CustomCredentialsAuthProvider.cs
示例7: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, System.Collections.Generic.Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
if (session.Email == AuthTestsBase.AdminEmail)
session.Roles.Add(RoleNames.Admin);
}
开发者ID:nstjelja,项目名称:ServiceStack,代码行数:7,代码来源:PageBase.cs
示例8: 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, IUserAuthRepository authRepo, IOAuthTokens 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 = AuthService.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.RequestContext.Get<IHttpResponse>();
if (httpRes != null)
{
httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
}
OnSaveUserAuth(authService, session);
}
开发者ID:yeurch,项目名称:ServiceStack,代码行数:34,代码来源:AuthProvider.cs
示例9: GetUserAuth
public UserAuth GetUserAuth(IAuthSession authSession, IOAuthTokens 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;
var oAuthProvider = Session.QueryOver<UserOAuthProviderPersistenceDto>()
.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;
}
开发者ID:JackFong,项目名称:ServiceStack.Contrib,代码行数:31,代码来源:NHibernateUserAuthRepository.cs
示例10: LoadUserAuth
public void LoadUserAuth(IAuthSession session, IOAuthTokens tokens)
{
session.ThrowIfNull("session");
var userAuth = GetUserAuth(session, tokens);
LoadUserAuth(session, userAuth);
}
开发者ID:JackFong,项目名称:ServiceStack.Contrib,代码行数:7,代码来源:NHibernateUserAuthRepository.cs
示例11: LoadUserAuthInfo
protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
var user = Repository.RepoUsers.GetUserByUserNameOrEmail(userSession.UserAuthName, userSession.UserAuthName);
userSession.Email = user.Email;
userSession.UserName = user.UserName;
base.LoadUserAuthInfo(userSession, tokens, authInfo);
}
开发者ID:sufong2001,项目名称:XpmsAzure,代码行数:8,代码来源:XpmsAuthProvider.cs
示例12: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
//Fill the IAuthSession with data which you want to retrieve in the app eg:
//session.FirstName = "some_firstname_from_db";
//...
//Important: You need to save the session!
authService.SaveSession(session, SessionExpiry);
}
开发者ID:writeameer,项目名称:ServiceStackRazor,代码行数:9,代码来源:CustomCredentialsAuthProvider.cs
示例13: IsAuthorized
public override bool IsAuthorized(IAuthSession session, IOAuthTokens tokens, Auth request = null)
{
if (request != null)
{
if (!LoginMatchesSession(session, request.UserName)) return false;
}
return tokens != null && !string.IsNullOrEmpty(tokens.AccessTokenSecret);
}
开发者ID:grammarware,项目名称:fodder,代码行数:9,代码来源:src_ServiceStack_ServiceInterface_Auth_OAuthProvider.cs
示例14: OnAuthenticated
public override void OnAuthenticated(
IServiceBase authService,
IAuthSession session,
IOAuthTokens 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.TranslateTo<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 == GoogleOpenIdOAuthProvider.Name)
{
user.GoogleUserId = authToken.UserId;
user.GoogleFullName = authToken.FullName;
user.GoogleEmail = authToken.Email;
if (user.Email == null) user.Email = user.GoogleEmail;
if (user.UserName == null) user.UserName = user.GoogleUserId;
}
else if (authToken.Provider == YahooOpenIdOAuthProvider.Name)
{
user.YahooUserId = authToken.UserId;
user.YahooFullName = authToken.FullName;
user.YahooEmail = authToken.Email;
}
}
var adminUserNames = AppHost.AppConfig.AdminUserNames;
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 }
});
//authService.TryResolve<IDbConnectionFactory>().Run(db => db.Save(user));
}
}
//Resolve the DbFactory from the IOC and persist the user info
}
开发者ID:robertdean,项目名称:RavenMDB2,代码行数:57,代码来源:CustomUserSession.cs
示例15: IsAuthorized
public override bool IsAuthorized(IAuthSession session, IOAuthTokens tokens, Auth request = null)
{
if (BlackListRepository.Blacklist.Contains(session.Id))
return false;
bool isAuthorized = base.IsAuthorized(session, tokens, request);
return isAuthorized;
}
开发者ID:jwelgemoed,项目名称:SingletonTheory.Services,代码行数:9,代码来源:AuthProvider.cs
示例16: LoadUserOAuthProvider
/// <summary>Loads user o authentication provider.</summary>
///
/// <param name="authSession">The user session.</param>
/// <param name="tokens"> The tokens.</param>
public override void LoadUserOAuthProvider(IAuthSession authSession, IOAuthTokens 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;
}
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:13,代码来源:TwitterAuthProvider.cs
示例17: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens,
Dictionary<string, string> authInfo)
{
//Fill IAuthSession with data you want to retrieve in the app eg:
//Load the Session Object
session.FirstName = "some_firstname_from_db";
session.LastName = "some_last_name_from_db";
authService.SaveSession(session, SessionExpiry);
}
开发者ID:rafareyes7,项目名称:UnifyWS,代码行数:10,代码来源:AppHost.cs
示例18: LoadUserOAuthProvider
public override void LoadUserOAuthProvider(IAuthSession authSession, IOAuthTokens tokens)
{
var userSession = authSession as AuthUserSession;
if (userSession == null) return;
userSession.DisplayName = tokens.DisplayName ?? userSession.DisplayName;
userSession.FirstName = tokens.FirstName ?? userSession.FirstName;
userSession.LastName = tokens.LastName ?? userSession.LastName;
userSession.PrimaryEmail = tokens.Email ?? userSession.PrimaryEmail ?? userSession.Email;
}
开发者ID:rasikas,项目名称:SocialBootstrapApi,代码行数:10,代码来源:StsAuthProvider.cs
示例19: CreateOrMergeAuthSession
public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens)
{
using (var uow = GetUnitOfWork())
{
var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth();
var oAuthProvider = uow.GetSession().QueryOver<UserOAuthProviderPersistenceDto>()
.Where(x => x.Provider == tokens.Provider)
.And(x => x.UserId == tokens.UserId)
.SingleOrDefault();
if (oAuthProvider == null)
{
oAuthProvider = new UserOAuthProviderPersistenceDto
{
Provider = tokens.Provider,
UserId = tokens.UserId,
};
}
oAuthProvider.PopulateMissing(tokens);
userAuth.PopulateMissing(oAuthProvider);
userAuth.Email = oAuthProvider.Email;
userAuth.ModifiedDate = DateTime.UtcNow;
if (userAuth.CreatedDate == default(DateTime))
userAuth.CreatedDate = userAuth.ModifiedDate;
var userAuthId = 0;
if (userAuth.Id == 0)
{
var camper = new Camper() {Email = userAuth.PrimaryEmail};
uow.Save(camper);
var userAuthDto = new UserAuthPersistenceDto(userAuth);
uow.Save(userAuthDto);
userAuthId = userAuthDto.Id;
}
else
{
userAuthId = userAuth.Id;
}
//oAuthProvider.UserAuthId = userAuth.Id;
oAuthProvider.UserAuthId = (int) userAuthId;
if (oAuthProvider.CreatedDate == default(DateTime))
oAuthProvider.CreatedDate = userAuth.ModifiedDate;
oAuthProvider.ModifiedDate = userAuth.ModifiedDate;
uow.Save(oAuthProvider);
uow.CommitTransaction();
return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture);
}
}
开发者ID:paaschpa,项目名称:myThat,代码行数:55,代码来源:NHibrenateUserAuthRepository.cs
示例20: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService,
IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
session.ReferrerUrl = referrerUrl;
session.IsAuthenticated = true;
var user = StorageManager.GetPartnerAccountByUsername(session.UserAuthName);
session.UserName = user.UserName;
session.Id = user.ClientId;
session.Roles = new List<string>() {user.Role.ToString()};
authService.SaveSession(session, new TimeSpan(7, 0, 0, 0));
}
开发者ID:TripThru,项目名称:Gateway,代码行数:11,代码来源:TripThruGatewayHost.cs
注:本文中的IOAuthTokens类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论