lacostabr / socialauth-net

Automatically exported from code.google.com/p/socialauth-net
0 stars 0 forks source link

Storing token in database #117

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to be able to store the token in a database. How would I go about 
doing this? Do you have any code examples?

Original issue reported on code.google.com by matthewb...@gmail.com on 18 Sep 2012 at 3:42

GoogleCodeExporter commented 9 years ago
Please refer to demo application's save/load token demo. It demonstrates show 
can you download a token on disk and later use that to auto-login. In your case 
instead of writing to disk it will be saving to database. I've coped some 
snippet from the demo page to give you a kick start

 var token = SocialAuthUser.GetCurrentUser().GetConnection((PROVIDER_TYPE)Enum.Parse(typeof(PROVIDER_TYPE), ddlConnectedProviders.SelectedItem.Value)).GetConnectionToken();
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new FileStream(Server.MapPath("~/temptokens/MyFile.token"),
                                     FileMode.Create,
                                     FileAccess.Write, FileShare.Write);
            formatter.Serialize(stream, token);
            stream.Close();
            stream.Dispose();

            Response.ClearHeaders();
            Response.ClearContent();
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", "MyFile.token"));
            Response.WriteFile("~/temptokens/MyFile.token");

Deepak

Original comment by daggar...@brickred.com on 21 Sep 2012 at 8:51