Пример #1
0
    public static Response CheckUserIsNothAuthorisedByFacebookAnymore(NancyContext context)
    {
        long?facebookId = null;

        try
        {
            if (AuthenticatedUserNameHasValue(context))
            {
                facebookId = long.Parse(context.Items[SecurityConventions.AuthenticatedUsernameKey].ToString());
                var     user   = InMemoryUserCache.Get(facebookId.Value);
                var     client = new FacebookClient(user.AccessToken);
                dynamic me     = client.Get("me");
            }
        }
        catch (FacebookOAuthException)
        {
            //If an exception gets thrown the access token is no longer valid
            RemoveUserFromCache(context, facebookId);
            return(new Response()
            {
                StatusCode = HttpStatusCode.Unauthorized
            });
        }
        return(context.Response);
    }
Пример #2
0
        public MainModule()
        {
            this.RequiresAuthentication();

            Get["/"] = parameters =>
            {
                var     facebookId = long.Parse(Context.Items[SecurityConventions.AuthenticatedUsernameKey].ToString());
                var     user       = InMemoryUserCache.Get(facebookId);
                var     client     = new FacebookClient(user.AccessToken);
                dynamic me         = client.Get("me");
                return("<h1>Welcome to Social Democracy! " + me.name + "</h1><p>You have logged in using facebook</p>");
            };
        }