本文整理汇总了C#中IServiceBase.SaveSession方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceBase.SaveSession方法的具体用法?C# IServiceBase.SaveSession怎么用?C# IServiceBase.SaveSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceBase
的用法示例。
在下文中一共展示了IServiceBase.SaveSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authenticate
public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
{
var tokens = Init(authService, ref session, request);
var httpRequest = authService.Request;
var error = httpRequest.QueryString["error_reason"]
?? httpRequest.QueryString["error"]
?? httpRequest.QueryString["error_code"]
?? httpRequest.QueryString["error_description"];
var hasError = !error.IsNullOrEmpty();
if (hasError)
{
Log.Error("Facebook error callback. {0}".Fmt(httpRequest.QueryString));
return authService.Redirect(session.ReferrerUrl);
}
var code = httpRequest.QueryString["code"];
var isPreAuthCallback = !code.IsNullOrEmpty();
if (!isPreAuthCallback)
{
var preAuthUrl = PreAuthUrl + "?client_id={0}&redirect_uri={1}&scope={2}"
.Fmt(AppId, this.CallbackUrl.UrlEncode(), string.Join(",", Permissions));
authService.SaveSession(session, SessionExpiry);
return authService.Redirect(preAuthUrl);
}
var accessTokenUrl = this.AccessTokenUrl + "?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}"
.Fmt(AppId, this.CallbackUrl.UrlEncode(), AppSecret, code);
try
{
var contents = accessTokenUrl.GetStringFromUrl();
var authInfo = HttpUtility.ParseQueryString(contents);
tokens.AccessTokenSecret = authInfo["access_token"];
session.IsAuthenticated = true;
authService.SaveSession(session, SessionExpiry);
OnAuthenticated(authService, session, tokens, authInfo.ToDictionary());
//Haz access!
return authService.Redirect(session.ReferrerUrl.AddHashParam("s", "1"));
}
catch (WebException we)
{
var statusCode = ((HttpWebResponse)we.Response).StatusCode;
if (statusCode == HttpStatusCode.BadRequest)
{
return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "AccessTokenFailed"));
}
}
//Shouldn't get here
return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "Unknown"));
}
示例2: 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));
}
示例3: 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);
}
示例4: 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));
}
示例5: 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;
}
示例6: 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);
}
示例7: 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);
}
示例8: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
// Note:
// `session.UserAuthName` is already set to the user's user name.
// we use `session.UserName` for the user's secret unique id.
var usersRepo = authService.TryResolve<IUsersRepository>();
var user = usersRepo.GetOrCreateUser(session.UserAuthName);
session.UserName = user.UserId;
authService.SaveSession(session);
}
示例9: 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));
}
示例10: 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 = "garrett";
session.Roles = new List<string>();
session.Roles.Add("users");
session.Roles.Add("admins");
//...
//Important: You need to save the session!
authService.SaveSession(session, SessionExpiry);
}
示例11: Authenticate
public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request)
{
var tokens = Init(authService, ref session, request);
//TODO: For now, later check for incoming URL to see from where it comes and decide...
bool isAuthenticated = this.IsAuthorizedBySts(session, null, request);
if (!isAuthenticated)
{
authService.SaveSession(session, SessionExpiry);
return AuthenticateWithSTS(authService, session, request);
}
return CompleteAuthentication(authService, session, request, tokens);
}
示例12: OnAuthenticated
public override ServiceStack.Web.IHttpResult OnAuthenticated(IServiceBase authService, IAuthSession session,
IAuthTokens tokens, Dictionary<string, string> authInfo)
{
//Fill IAuthSession with data you want to retrieve in the app eg:
session.FirstName = "FirstName";
session.LastName = "LastName";
session.DisplayName = "Display Name";
session.Email = "[email protected]";
session.IsAuthenticated = true;
session.UserName = "Username";
session.UserAuthId = "001";
//...
//Important: You need to save the session!
authService.SaveSession(session, SessionExpiry);
return default(ServiceStack.Web.IHttpResult);
}
示例13: Authenticate
/// <summary>
/// The entry point for all AuthProvider providers. Runs inside the AuthService so exceptions are treated normally.
/// Overridable so you can provide your own Auth implementation.
/// </summary>
/// <param name="authService"></param>
/// <param name="session"></param>
/// <param name="request"></param>
/// <returns></returns>
public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
{
var tokens = Init(authService, ref session, request);
//Default OAuth logic based on Twitter's OAuth workflow
if (!tokens.RequestToken.IsNullOrEmpty() && !request.oauth_token.IsNullOrEmpty())
{
OAuthUtils.RequestToken = tokens.RequestToken;
OAuthUtils.RequestTokenSecret = tokens.RequestTokenSecret;
OAuthUtils.AuthorizationToken = request.oauth_token;
OAuthUtils.AuthorizationVerifier = request.oauth_verifier;
if (OAuthUtils.AcquireAccessToken())
{
tokens.AccessToken = OAuthUtils.AccessToken;
tokens.AccessTokenSecret = OAuthUtils.AccessTokenSecret;
session.IsAuthenticated = true;
OnAuthenticated(authService, session, tokens, OAuthUtils.AuthInfo);
authService.SaveSession(session, SessionExpiry);
//Haz access!
return authService.Redirect(session.ReferrerUrl.AddHashParam("s", "1"));
}
//No Joy :(
tokens.RequestToken = null;
tokens.RequestTokenSecret = null;
authService.SaveSession(session, SessionExpiry);
return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "AccessTokenFailed"));
}
if (OAuthUtils.AcquireRequestToken())
{
tokens.RequestToken = OAuthUtils.RequestToken;
tokens.RequestTokenSecret = OAuthUtils.RequestTokenSecret;
authService.SaveSession(session, SessionExpiry);
//Redirect to OAuth provider to approve access
return authService.Redirect(this.AuthorizeUrl
.AddQueryParam("oauth_token", tokens.RequestToken)
.AddQueryParam("oauth_callback", session.ReferrerUrl));
}
return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "RequestTokenFailed"));
}
示例14: Authenticate
public override object Authenticate(IServiceBase service, OAuth request, IOAuthSession session, IOAuthTokens tokens, OAuthAuthorizer oAuth)
{
var code = service.RequestContext.Get<IHttpRequest>().QueryString["code"];
var isPreAuthCallback = !code.IsNullOrEmpty();
if (!isPreAuthCallback)
{
var preAuthUrl = PreAuthUrl + "?client_id={0}&redirect_uri={1}&scope={2}"
.Fmt(AppId, this.CallbackUrl.UrlEncode(), string.Join(",", Permissions));
return service.Redirect(preAuthUrl);
}
var accessTokenUrl = this.AccessTokenUrl + "?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}"
.Fmt(AppId, this.CallbackUrl.UrlEncode(), AppSecret, code);
try
{
var contents = accessTokenUrl.DownloadUrl();
var authInfo = HttpUtility.ParseQueryString(contents);
tokens.AccessTokenSecret = authInfo["access_token"];
service.SaveSession(session);
session.OnAuthenticated(service, tokens, authInfo.ToDictionary());
//Haz access!
return service.Redirect(session.ReferrerUrl.AddQueryParam("s", "1"));
}
catch (WebException we)
{
var statusCode = ((HttpWebResponse)we.Response).StatusCode;
if (statusCode == HttpStatusCode.BadRequest)
{
return service.Redirect(session.ReferrerUrl.AddQueryParam("f", "AccessTokenFailed"));
}
}
//Shouldn't get here
return service.Redirect(session.ReferrerUrl.AddQueryParam("f", "Unknown"));
}
示例15: ValidateAccount
protected virtual IHttpResult ValidateAccount(IServiceBase authService, IAuthRepository authRepo, IAuthSession session, IAuthTokens tokens)
{
var userAuth = authRepo.GetUserAuth(session, tokens);
var isLocked = userAuth != null && userAuth.LockedDate != null;
if (isLocked)
{
session.IsAuthenticated = false;
authService.SaveSession(session, SessionExpiry);
return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "AccountLocked"));
}
return null;
}