mercredi 23 décembre 2015

Making calls to Parse REST API while using Parse .NET SDK

I am making the great sin of using Parse.com backend in my ASP.NET MVC application. As we all know, the Parse .NET SDK saves the currentUser to the web server when you use the SDK out of the box, so everyone who hits that server can see the currently logged in account, making Parse.com and ASP.NET unusable together right now.

However, I've got a workaround in place for that.

    var user = await ParseUser.LogInAsync(vm.Email, vm.Password);
               ParseHelper.StoreSessionToken(HttpContext);

And so then the StoreSessionToken method does this.

    public static void StoreSessionToken(HttpContextBase context)
    {
        var task = ParseSession.GetCurrentSessionAsync();
        task.Wait();
        var session = task.Result;
        context.Session[ParseHelper.PARSE_SESSION_TOKEN] = session.SessionToken;
    }

When I need to get the currentUser I use this method.

public static ParseUser GetCurrentUser(HttpContextBase context)
    {
        var token = context.Session[PARSE_SESSION_TOKEN];
        if (token == null) return null;

        var task = ParseUser.BecomeAsync(token.ToString());
        try
        {
            task.Wait();
        }
        catch (Exception e)
        {
            DeleteSession(context);
            return null;
        }

        return task.Result;
    }

As far as my testing has shown this is fine, but obviously when signing up / logging in you are constantly changing the static currentUser on disk and quickly grabbing that session token which will become more and more unstable as more users, use this app.

What I would like to do is write authentication methods for Signing up, logging in, and retrieving current user using Parse's REST API. Then I wouldn't have to bother with setting the currentUser on disk, eliminating that problem and I could then just continue using the session token to retrieve the current user and their relevant data.

Is it possible to make REST calls to Parse while using the .NET SDK and do you think this is a reasonable solution?




Aucun commentaire:

Enregistrer un commentaire