Get Current User after SignInStatus.Success - asp.net-mvc-5

I have a mvc app and I´m using Asp Identity 2.0. I need to change some User information after the login, so I need to get the current user just after login. I´m using the following code
var user = UserManager.FindById(User.Identity.GetUserId());
Just after
case SignInStatus.Success:
But I´m getting null as result. Usually when I use UserManager.FindById(User.Identity.GetUserId()) in the Controllers it works fine. Don´t know what is happening now.

Related

Cors no-access-control-allow-origin when trying to call B2C login

I cannot resolve this error, i have a .net core web api, with a react application inside of it ( net core react template )
I have also added cors:
services.AddCors(options =>
{
options.AddPolicy("AllowMyOrigin",
builder => builder.WithOrigins("https://localhost:44300")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
);
});
I have tried multiple things but i cant get past this error.
I have found loads of material online to try and nothing seems to work i feel like i am missing something really obvious?
Can someone point me in the right direction.
I expect that there should be an allow origin header:
I also tried using the Mosif browser extension to turn cors on, this stoped the cors error from showing but now i have a 404 (notfound ) on:
https://login.microsoftonline.com/tfp/domainname.onmicrosoft.com/b2c_1_sign_up/v2.0/.well-known/openid-configuration
You mention that you get an 404 error when opening the openid-configuration url. This means that part of your configuration is incorrect. You must be able to open this url in your browser and get back a JSON document. Copy it to a new tab and tweak it until you get back a result.
Please double check your configured policy and tenant name. The full url usually looks like this:
https://tenantname.b2clogin.com/tenantname.onmicrosoft.com/<policy-name>/v2.0/.well-known/openid-configuration
https://tenantname.b2clogin.com/tenantname.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=<policy-name>
https://login.microsoftonline.com/tfp/tenantname.onmicrosoft.com/<policy-name>/v2.0/.well-known/openid-configuration
All of these are equally valid and can be used depending on your scenario.
The config should then look something like this:
authentication.initialize({
instance: 'https://tenantname.b2clogin.com/',
tenant: 'tenantname.onmicrosoft.com',
Another issue might be if your B2C tenant quite new, Microsoft could be blocking support for microsoftonline for your tenant. In this case, try switching to the b2clogin.com domain as your instance.
You can see a possible value for this url when opening the user flow in the Azure Portal.
As a sidenote, I would suggest switching to a different react library. The one you are using is not really being maintained. We are currently using https://github.com/syncweek-react-aad/react-aad

Google API SignIn HostedDomain cleanup problem

We implement the Sign-In on iOS using the Google API in our project. Customers must have a possibility to select the HostedDomain to limit the allowed account pull to the single domain.
SignIn.SharedInstance.HostedDomain = "domainName.com";
works perfectly.
The problem is when we want to Logout the user and log in it back with unrestricted HostedDomain
SignIn.SharedInstance.HostedDomain == null; // <-Default Value
When I try to set it to
SignIn.SharedInstance.HostedDomain=string.empty;
I filter everything.
When I try to set it to null
SignIn.SharedInstance.HostedDomain=null;
I get the exception.
Calling:
SignIn.SharedInstance.Dispose();
doesn't help.
The question is: How is possible to reset the HostedDomain filtering to the initial stage - allow everything without of the app restart.
Our implementation based on Xamarin iOS native, but we see the same problem in Swift or Objective-C.
The wrapper for the Gooogle SDK we use:
Xamarin.Google.iOS.SignIn

sailsjs waterlock get jwt on login successful and signup with more fields

I am using waterlock for authentication in sailsjs application. Everything is working fine. I need two customization.
Here to get token we need to follow two steps. http://example.com/auth/login and then http://example.com/user/jwt . What we need is token should return after successful login , i.e. http://example.com/auth/login should return token after successfull login.
When user try to login with credential by this URL : http://example.com/auth/login
If email id is not present waterlock create a new user with this email. We need to stop this because we have another mandatory fields to sign up a user like name, phone number etc.
Please tell me what needs to be done here.
I had exactly these issues yesterday as well and I was able to solve them:
I needed the user as well as the token on loggin. Go into your config/waterlock.js and look for the postAction on login and change the section to the following. Change success: 'default' to success: 'jwt'.
If you dont want to create a user if it doenst exist yet edit the following line in config/waterlock.js in the authMethod: createOnNotFound: false
I hope this helps.

web site scraping through Jsoup

I have spent few hours on signing in to web site by using jsoup. But it always gives same login page. To clarify the issue I tried with facebook site. It also gives same result.
Below I mentioned my code
String url ="http://www.facebook.com/";
Document doc;
doc = Jsoup.connect(url)
.data("email","abc#gmail.com","pass","xyz")
.userAgent("Mozilla").post();
System.out.println(doc);
can anybody point me where I made a mistake and how can i fix this issue?
In data portion "email" and "pass" are input field id of facebook login page.
Thank you.
Try this:
String url ="http://www.facebook.com/";
Document doc;
doc = Jsoup.connect(url)
.data("email","abc#gmail.com")
.data("pass","xyz")
.userAgent("Mozilla")
.post();
Anyway, Jsoup is not bad at all, you only need how to use it properly, but also you need to keep in mind that Facebook is expecting a lot more parameters to make a successfull login via POST emulating a web page navigation.
By example:
charset_test
default_persistent
lgnjs
lgnrnd
locale
lsd
pass
persistent
timezone
If you need to authenticate and get proper data I suggest that you must give a try to a Facebook SDK for Android:
https://github.com/facebook/facebook-android-sdk/

Flickr/flickrj: how to get user information after user clicks on web-app?

I'm writing a Java web-app that I created a Flickr-app for.
If a Flickr-user registers my app he/she is automatically sent to the URL I entered in Flickr's authentication flow of the app. Along with that I receive a parameter frob. I can use that one to get the Flickr's user-id of that particular user:
flickrId = flickrj.getAuthInterface().getToken(frob).getUser().getId();
So that works fine.
However, if he/she uses the screen "Apps You're Using" and clicks on my app I don't get any information about the user as far as I can tell. Nonetheless, if I use flickrj like
frob = flickrj.getAuthInterface().getFrob();
I get a frob like 7x1x7x2x2x8x1x1x0-48x9f1xfdbx8ex9d-x00x5x9(note that I x-ed some numbers), whatever that frob is supposed to be. If I then use that frob on
flickrId = flickrj.getAuthInterface().getToken(frob).getUser().getId();
I run into a
com.aetrion.flickr.FlickrException: 108: Invalid frob
at com.aetrion.flickr.auth.AuthInterface.getToken(AuthInterface.java:182)
:
What do I need to do to get information about Flickr's currently logged in user? I had hoped to find something like a place-holder I can use in that URL or Flickr automatically sends some parameter, but I couldn't find information about this.
After some more trial and error I simply use the permission URL that flickrj creates.
String frob = flickrj.getAuthInterface().getFrob();
return "redirect:" + flickrj.getAuthInterface().buildAuthenticationUrl(Permission.READ, frob);
This calls the URL I entered in Flickr's authentication flow of the app. The only problem is to distinguish from such a request to when the user came in from Flickr's authorization form.
But that's another story...

Resources