I needed to do this today for my Ionic app. The web API account controller has its own opinion on how to do this, and the best way to figure it out is with a rather interesting 3-page blog post by Dominic Bayer. https://leastprivilege.com/2013/11/26/dissecting-the-web-api-individual-accounts-templatepart-3-external-accounts/ .
The way I worked on this was to forget the stream out of the box, but instead use accessToken from my own Facebook login and then call the following server code: 1) call the Facebook API to check the access token, 2) from this Facebook call, get the email and ID, 3) either get the user, or create one (and log in), which is already a code that is in the account controller in other places, 4) create a local JWT authority for subsequent calls Web API
public class ProviderAndAccessToken { public string Token { get; set; } public string Provider { get; set; } } [AllowAnonymous] [HttpPost] [Route("JwtFromProviderAccessToken")] public async Task<IHttpActionResult> JwtFromProviderAccessToken(ProviderAndAccessToken model) { string id = null; string userName = null; if (model.Provider == "Facebook") { var fbclient = new Facebook.FacebookClient(model.Token); dynamic fb = fbclient.Get("/me?locale=en_US&fields=name,email"); id = fb.id; userName = fb.email; }
The code I use in Ionic basically does this in order to get the access token from Facebook and then call the web API to use the local authority JWT to use as the media token.
Facebook.login(['public_profile', 'email']).then((result) => { return this.http.post("<URL>/api/Account/JwtFromProviderAccessToken", { provider: "Facebook", token: result.authResponse.accessToken }) .map((res: Response) => res.json()) .catch(this.handleError) .subscribe((res: Response) => { // use the result as the Bearer token }); })...
It seems pretty safe, but understand that I am not a security expert, so this code comes with no guarantee, and please let me know if you see anything blatant and I will update the code.
Sean chase
source share