Assign token to logged in user

I have an application using PCL that allows users to use the app once they've logged in via facebook. I've done much research but haven't found a way to assign each logged in user with a unique token. This token will be the primary key to identifying user-specific details in the app. Any help on how to go about doing this will be appreciated. Thanks.

FacebookRender class in Droid:
namespace LoyaltyWorx.Droid
{
public class FacebookRender : PageRenderer
{
public FacebookRender()
{
var activity = this.Context as Activity;

            var auth = new OAuth2Authenticator(
                clientId: "",
                scope: "",
                authorizeUrl: new Uri("https://www.facebook.com/dialog/oauth/"),
                redirectUrl: new Uri("https://www.facebook.com/connect/login_success.html")
                );

            auth.Completed += async (sender, eventArgs) =>
                {
                    if (eventArgs.IsAuthenticated)
                    {
                        var accessToken = eventArgs.Account.Properties["access_token"].ToString();
                        var expiresIn = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]);
                        var expiryDate = DateTime.Now + TimeSpan.FromSeconds(expiresIn);

                        var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, eventArgs.Account);
                        var response = await request.GetResponseAsync();
                        var obj = JObject.Parse(response.GetResponseText());

                        var id = obj["id"].ToString().Replace("\"", "");
                        var name = obj["name"].ToString().Replace("\"", "");

                        App.NavigateToProfile(string.Format(name));
                    }
                    else
                    {
                        App.NavigateToProfile("Invalid Login");
                    }
                };
            activity.StartActivity(auth.GetUI(activity));
        }
    }

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Have you tried a GUID? They are unique

  • Programmer00_Programmer00_ ZAMember ✭✭

    @ClintStLaurent I thought of that, problem is I'm not sure how to implement it to each user that logs in :s

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    So the question really is: "How do I architect my user, app and solution?"
    Sorry... Can't help you design your entire app architecture.

  • Programmer00_Programmer00_ ZAMember ✭✭

    @ClintStLaurent didn't ask you to design anything. I asked for guidance, a simple explanation on how to accomplish it, a simple nudge in the right direction. But thank you.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    "How do I impliment {...}" - is another way to ask "How do I architect/design {...}"
    You are asking "How do I track features by user?"
    Literally > I'm not sure how to implement it to each user that logs in

    So yeah, you're asking someone to explain to you how to implement GUIDs as properties on your user object, how to track features/permissions on each user... how to architect the logic of your app with respect to user rights and permissions.

    I was hesitant to comment on the question at all but thought I would give that gentle nudge - Use GUID
    But that wasn't enough because your reply was basically "Okay, now show me how"
    Clearly it was my mistake - not yours. One I won't make again.

Sign In or Register to comment.