I don’t know if you finally found a solution, but I am trying to do something quite similar, and I am still collecting puzzle pieces. I tried to post this as a comment instead of an answer, since I am not proposing a real solution, but it is too long.
Obviously, all OAPA parameters for Owin WebAPI are browser-based, that is, they require a large number of browser redirection requests that are not suitable for the native mobile application (in my case). I'm still learning and experimenting, but as Hongye Sun briefly described in one of the comments on his blog post, http://blogs.msdn.com/b/webdev/archive/2013/09/20/understanding-security-features -in-spa-template.aspx? PageIndex = 2 # comments , in order to enter the access token obtained via the Facebook SDK from Facebook, the API can be checked directly by creating a graph call to the / me endpoint.
Using the information returned by the graph call, you can check whether the user is registered or not. In the end, we need to sign the user, possibly using the Authentication.SignIn Owin method, returning the carrier token that will be used for all subsequent API calls.
EDIT: Actually, I realized that the carrier token is issued when the "/ Token" endpoint is called, which at the input accepts something like grant_type=password&username=Alice&password=password123 The problem here is that we don’t have a password (that's all points to the OAuth mechanism), so how else can you call the "/ Token" endpoint?
UPDATE: I finally found a working solution, and here is what I had to add to the existing classes to make it work: Startup.Auth.cs
public partial class Startup {
In AccountController, I added the following action
[HttpPost] [AllowAnonymous] [Route("FacebookLogin")] public async Task<IHttpActionResult> FacebookLogin(string token) { [Code to validate input...] var tokenExpirationTimeSpan = TimeSpan.FromDays(14); ApplicationUser user = null; // Get the fb access token and make a graph call to the /me endpoint // Check if the user is already registered // If yes retrieve the user // If not, register it // Finally sign-in the user: this is the key part of the code that creates the bearer token and authenticate the user var identity = new ClaimsIdentity(Startup.OAuthBearerOptions.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, user.Id, null, "Facebook")); // This claim is used to correctly populate user id identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id, null, "LOCAL_AUTHORITY")); AuthenticationTicket ticket = new AuthenticationTicket(identity, new AuthenticationProperties()); var currentUtc = new Microsoft.Owin.Infrastructure.SystemClock().UtcNow; ticket.Properties.IssuedUtc = currentUtc; ticket.Properties.ExpiresUtc = currentUtc.Add(tokenExpirationTimeSpan); var accesstoken = Startup.OAuthBearerOptions.AccessTokenFormat.Protect(ticket); Authentication.SignIn(identity); // Create the response JObject blob = new JObject( new JProperty("userName", user.UserName), new JProperty("access_token", accesstoken), new JProperty("token_type", "bearer"), new JProperty("expires_in", tokenExpirationTimeSpan.TotalSeconds.ToString()), new JProperty(".issued", ticket.Properties.IssuedUtc.ToString()), new JProperty(".expires", ticket.Properties.ExpiresUtc.ToString()) ); var json = Newtonsoft.Json.JsonConvert.SerializeObject(blob); // Return OK return Ok(blob); }
What is it. The only difference I found with the answer to the classic / Token endpoint is that the carrier token is a little shorter and the expiration and release dates are in UTC and not GMT (at least on my machine).
Hope this helps!