How to make Facebook Authentication from Silverlight secure?
Posted
by SondreB
on Stack Overflow
See other posts from Stack Overflow
or by SondreB
Published on 2010-06-13T13:13:10Z
Indexed on
2010/06/13
19:02 UTC
Read the original article
Hit count: 380
I have the following scenario I want to complete:
- Website running some HTTP(S) services that returns data for a user.
- Same website is additionally hosting a Silverlight 4 app which calls these services.
- The Silverlight app is integrating with Facebook using the Facebook Developer Toolkit (http://facebooktoolkit.codeplex.com/).
I have not fully decided whether I want Facebook-integration to be a "opt-in" option such as Spotify, or if I want to "lock" down my service with Facebook-only authentication. That's another discussion.
How do I protect my API Key and Secret that I receive from Facebook in a Silverlight app? To me it's obvious that this is impossible as the code is running on the client, but is there a way I can make it harder or should I just live with the fact that third parties could potentially "act" as my own app?
Using the Facebook Developer Toolkit, there is a following C# method in Silverlight that is executed from the JavaScript when the user has fully authenticated with Facebook using the Facebook Connect APIs.
[ScriptableMember]
public void LoggedIn(string sessionKey, string secret, int expires, long userId)
{
this.SessionKey = sessionKey;
this.UserId = userId;
Obvious the problem here is the fact that JavaScript is injection the userId, which is nothing but a simple number. This means anyone could potentially inject a different userId in JavaScript and have my app think it's someone else. This means someone could hijack the data within the services running on my website.
The alternative that comes to mind is authenticating the users on my website, this way I'm never exposing any secrets and I can return an auth-cookie to the users after the initial authentication. Though this scenario doesn't work very well in an out-of-browser scenario where the user is running the Silverlight app locally and not from my website.
© Stack Overflow or respective owner