4

I am authenticating users via GoogleOpenIdOAuthProvider. I need to access the email address of the user that logged in. I have attempted to implement the Using Typed Sessions in ServiceStack code as-is.

So, I created a base class that my service inherits from:

public abstract class AppServiceBase : Service
{
    //private CustomUserSession userSession;
    protected CustomUserSession UserSession
    {
        get
        {
            return base.SessionAs<CustomUserSession>();
        }
    }
}

public class CustomUserSession : AuthUserSession
{
    public string CustomId { get; set; }
}

The service has the [Authenticate] attribute on it. In my AppHost setup, I have configured auth like this:

        Plugins.Add(new AuthFeature(() => new CustomUserSession(),
            new IAuthProvider[] {
            new GoogleOpenIdOAuthProvider(appSettings)    //Sign-in with Google OpenId
        }));

Once the user has authenticated, the service tries to access the auth session from the base class like this:

var x = base.UserSession.Email;

However, Email is always null. How can I access this value?

4

1 回答 1

3

您需要从 AuthProvider 中提取数据并在 CustomUserSession 中设置值。SocialBootstrapApi 示例中显示了一个示例

https://github.com/ServiceStack/SocialBootstrapApi/blob/master/src/SocialBootstrapApi/Models/CustomUserSession.cs#L50

覆盖 OnAuthenticated,找到 GoogleOpenIdOAuthProvider 以获取电子邮件地址。

另一个示例显示在ServiceStack OAuth - 注册而不是登录

于 2013-04-22T18:45:20.130 回答