How can I get type of external login provider from authenticated user in ASP.MVC 4? - model-view-controller

I'm using ASP.MVC 4 with an account controller that uses forms authentication. I added Facebook and Twitter as an external login providers using OAuthWebSecurity.RegisterFacebookClient etc. Now I want to get User login type (Facebook, Twitter, login/password etc) in the controller and in the view. How can I get this? Thank you.

I fount answer by myself in the AccountController, action RemoveExternalLogins :
ICollection<OAuthAccount> accounts = OAuthWebSecurity.GetAccountsFromUserName(User.Identity.Name);
and account contain provider field - account.Provider. For Facebook it will be "Facebook".

Related

How to register a normal user using django oAuth toolkit

I am using the Django-Oauth-toolkit in my web app development.In that i can able to create new application using django admin panel and created the new admin users.And i can able to login that newly created admin users and able to get the token.But my problem is, i can able to register the user using my model and user is created in my db.But when i try to login with created user and try to get token with o/token with oauth grand type, then i am not getting token and getting invalid credentials response.But super user credentials login and token generation is working fine.And in django admin panel, super users are listed under 'Authetication and authorization' and normal users are listed under Django app.So please help me how to generate the tokens for users which are registered in django app.Or how to create the super users from django app.
I hope you found a solution to your issue. I was facing the same problem, and stumble on this answer.
You should check it out.
On the other hand you should use django's createsuperuser command to add users, so that they are also registered in your django oauth toolkit application.

Dynamic user role assignment after socialite signup

I want to give social signup and registration for multiple users. Multiple types (roles) of user can sign up. That means I want a different registration page for each of them. Now, if I give them to sign up via Google option, how do I identify at the controller which role to assign to the new user? Basically, how do I identify which registration page was used before to sign up via Google?
I have tried using request()->server('HTTP_REFERER') but it returns Google's URL instead of my registration page.
When the user is on your registration page (before going to the social provider's login) you can store something in the session or in the browser's localStorage.
When the return comes back from the social provider's login you can retrieve the session or localStorage data and use that.

Lumen Socialite authorisation flow

Info
I'm looking for some clearification for using the Socialite package in a Lumen project. I want to use OAuth2 so users can authenticate with theire Google, Facebook or other social account on our applications.
To my understanding Socialite redirects to a page of the selected provider, asks the user for permission and return to the application with the authenticated user object. I made a base setup with a Laravel application and this all works fine.
The problem
I have an authentication API (Lumen based) where user credentials are validated. This is only a backend service. The actual user credentials are received from different front-ends (applications). Do the frontends need to implement OAuth2 / Socialite and send the social user details to my authorisation API or can the API arrange the whole OAuth2 process?
I don't quite get it how the redirection should take place in an if the whole flow is arranged by the API? There is a stateless() option available in socialite and i found some information where socialite is used in Lumen but then i don't get the whole redirect / authentication flow.
Options
Different optios
Like to hear from users if this option is possible, hope my question is clear. :)
Just to update on my own question;
After some research i found the flow to be like this:
-> Frontend handles the user request to be authorised by Oauth2 with a specific provider. (we get redirected to a page of the provider asking about permission for this application). This can be done with socialite (in case of Laravel) or any other package for a specific framwework.
-> An Access token is received by the frontend and send to our Lumen backend service. Here we can use Socialite again to get the user details for this access token. The user details can then be used to create a new user or attach a social login to an existing user. When access token is valid and user is created or found in existing user, the user can proceed in the application.
Hope to help someone in the future with the same questions :)

Laravel Stormpath Social Login Error

I am using Laravel 5.1 and Stormpath for User management.
I followed this documentation to implement google login
Configuring Your Social Provider = DONE
I created project in Google Console and in “Authorized redirect URIs” I've added
https://{DNS-LABEL}.apps.stormpath.io/authorize/callback
Create a Stormpath Social Directory = DONE
Initiate Social Login - In my form when I click on Google Sign In it redirects to
https://{DNS-LABEL}.apps.stormpath.io/?response_type=stormpath_token&
account_store_href=https://api.stormpath.com/v1/directories/{id}
&redirect_uri=https%3A%2F%2Flocalhost
and returns
{"status":404,"message":"Resource not found."}
As per this documentation:
The user clicks on a “Login with Google” link pointing at your application’s /authorize endpoint
Stormpath handles the login to Google and redirects the user back to your app with a Stormpath Token JWT response
What am I doing wrong? Why isn't stormpath redirecting to the google login page?
It looks like the URL that you are creating is missing the /authorize part. If you update your URL to be
https://{DNS-LABEL}.apps.stormpath.io/authorize?response_type=stormpath_token&
account_store_href=https://api.stormpath.com/v1/directories/{id}
&redirect_uri=https%3A%2F%2Flocalhost
It should begin working for you.
In a future release of the PHP SDK (which powers the laravel integration), we will be able to generate this URL for you.
If you are using our Stormpath/Laravel integration, the views provided will automatically handle social logic for you. If you are doing this from scratch, it may be worth a look at https://github.com/stormpath/stormpath-laravel
-Brian

TweetSharp - Get User Email ID after login

I am using TweetSharp for user login in my asp.net mvc web app. All works fine but after login I need to save the user data in my DB as well. I cant find email from TwitterUser object after loging. How can i get user's email once the user is authenticated?
thanks
You cannot. The Twitter API doesn't return email addresses for users.
Take a look at the users/show documentation to see all the information you can retrieve.
If your app is whitelisted, you can now retrieve the email as part of verify_credentials https://dev.twitter.com/rest/reference/get/account/verify_credentials

Resources