Login to ASP.NET Core API application from mobile with facebook - facebook-javascript-sdk

I need to create a web api using Asp.Net Core MVC. The will login in the mobile device using the Facebook SDK, but I need to authenticate the user at the server site.
How could I do this right?
thnx

Related

How .NET Core can authenticate from founded other app cookie?

An website created by Node.js/Express.js. Authentication provided by Passport.js. After login Express.js creates cookie.
Subdomain will be created with .Net Core. And it if found cookie, has to automatically authenticate user.
I know .Net Core Identity.
But I can't get any information in Google about this solution.
How .Net Core app can authenticate if cookie is founded?

authenticate from a website to an azure mobile app service

I have an Azure Mobile App service that I use with my (Cordova and Xamarin) mobile apps. The URL for the Mobile App service is https://gonzo.azurewebsites.net/ (not the real URL). I want to create a website (ASP.NET Core 2.0 Web App) that connects to my Azure Mobile App service, just like my apps do. I tried publishing it to the gonzo URL but that overwrote my mobile app service and thus I had to restore it. I’d love to know if there is a way to actually make that work.
My next step was to create the website and use a different URL https://kermit.azurewebsites.net/. I use social authentication for my app mobile service. When I debug it locally against localhost, everything works perfectly. The problem that I’m running into is that when I try to login from the published website, regardless of the auth provider (facebook, Microsoft, google), instead of getting to the login UI supplied by the login provider, I get a 403 with the URL looking something like this: https://gonzo.azurewebsites.net/.auth/login/facebook/callback?code=long-code.
I thought this can be fixed by allowing the kermit origin in my Azure Mobile App service in CORS. I even tried setting CORS to allow all hosts (*) but that didn’t make a difference. Any idea how to make this work?
I want to create a website (ASP.NET Core 2.0 Web App) that connects to my Azure Mobile App service, just like my apps do. I tried publishing it to the gonzo URL but that overwrote my mobile app service and thus I had to restore it. I’d love to know if there is a way to actually make that work.
Based on your requirement, I assumed that you could deploy your NET Core 2.0 Web App along with your mobile app, at this point your two applications could share the authentication. For Detailed tutorial, you could follow Deploying multiple virtual directories to a single Azure Website.
The problem that I’m running into is that when I try to login from the published website, regardless of the auth provider (facebook, Microsoft, google), instead of getting to the login UI supplied by the login provider, I get a 403 with the URL looking something like this: https://gonzo.azurewebsites.net/.auth/login/facebook/callback?code=long-code.
According to your description, you are using the App Service Authentication / Authorization. I would recommend you directly access https://<your-mobile-app-name>.azurewebsites.net/.auth/login/<provider-name> via the browser to make sure you have successfully set up the authentication for your mobile app.
If I understand you correctly that you want to create another Azure Web App to hosting your NET Core 2.0 Website, and your website wants to connect with your mobile app. Here are some approaches, you could refer to them:
For accessing mobile app in the front-end of your .Net Core web app
You could leverage the JavaScript SDK for Azure Mobile Apps in your .Net Core web app to access your mobile app. Details you could follow here. Additionally, if your website would also enable the app service authentication, you could just send GET https://<your-netcore-webapp-name>.azurewebsites.net/.auth/me to retrieve the access_token, then use the Client-managed authentication for logging with your mobile app in the front-end of your netcore website.
For accessing mobile app in the back-end of your .Net Core web app
I assume that your .Net Core web app would also need to enable social authentication via using the App Service Authentication / Authorization, and in the backend of your website you could retrieve the access_token for the current logged user, then you could use Client-managed authentication for logging with your mobile app. The logging request would look like this:
POST https://<your-mobile-app-name>.azurewebsites.net/.auth/login/<provider-name>
Payload: {"access_token":"<the-access-token-for-the-specific-social-provider>"}
Moreover, for retrieving the user logged infos (including the access_token,etc.) from App Service Authentication / Authorization (EasyAuth), you could follow this issue.

How to implement Facebook native app login in Ionic 3 with a .net Core API

I have a .Net Core Auth API with OpenIddict and a .Net Core Api 'client'. Now I'm building an Ionic 3 native app and I want to implement Facebook login where people can login via the native Facebook app. So far I only found examples where the Facebook web login is used.
So far I have:
a working .Net Core Auth API that returns Jwt tokens
a working .Net Core Client API that accepts these JWT tokens
a working Ionic 3 app that can login with username + password, get a token and use it.
a working Ionic 3 app with a Facebook login that logs in via the native Facebook app (via Cordova plugin)
It feels like the Code flow is the correct way to go, but all examples redirects to the Facebook login web page so the user probably still has to log in on Facebook while his native Facebook app is already logged in.
My question is: after a user is logged in via Facebook in my Ionic app, how can I get a JWT Token from the OpenIddict Auth Api so I can use my client API? Or should I change the flow somehow while the native Facebook app is used to log in?
update: In Ionic I do get Facebook UserId which is equal to the AspNetUserLogins.ProviderKey. Is that secure enough to login to your Api?
If using the code flow or opening the system browser to complete the authentication process interactively (including the FB authentication step) is definitely not an option for you, consider using a custom grant to allow your mobile app to redeem a FB access token (or authorization code) with an access token issued by OpenIddict.
For more information, see this other SO thread: Rich Twitter Digits/Google Auth with OpenIdDictServer

How to authenticate to a custom oAuth2 server using an existing Facebook Login ticket

I would like to authenticate a user from both a mobile app and a website, using a separate oAuth2 server (let say Identityserver4 and call it AUTHSERVER).
Both mobile app and the website have their own "Connect with Facebook" button, which uses the Facebook SDK. After a succesful Facebook login, the app/website get a Facebook ticket.
What is the standard flow to use this ticket with the existing oAuth2 server ?
I found this article How to sign in user on .NET Core server after authentication on Mobile App which does that manually using a custom API action.
I'm using dot.net core.
== EDIT ==
Finally will not use IdentityServer4, but a custom solution.
== EDIT2 ==
Found manual solution here
https://developers.google.com/identity/sign-in/web/backend-auth

Google Analytics API Using Asp.net

i am developing a web application using Asp.net MVC but
i am struck in a Proof Concept application. i am unable to authenticate user with Oauth using WEB APPlication.
How i authenticate user using gmail account for google analytics api for my web application.
any suggestion or work around.