Autheticate via SAML and create token in API - php

I am working on SAML authentication for my application which has the following architecture.
Frontend application written in Laravel - does not handle authentication
Backed API also written in Laravel which handles authentication
What I have now is a login form that has a login with SAML button which uppon clicked redirects to a Microsoft page and redirects a callback page on the frontend application with information from the saml request.
Now I need to authenticate the user and create a token, then make a session in the frontend application.
Since I was using SAML, I have no password to do a traditional authenticate.
This would mean that I need some API to which I pass some info from SAML to be able to check whether that email exists in the db and subsequently created a token.
But since this API is public, I can't just pass an email because that would allow someone to guess it.
How do I prevent this?

redirects a callback page on the frontend application with information
from the saml request
the information from the SAML request is your authentication event. The user has authenticated to your application by logging in at their Identity Provider (Microsoft page) and returning to your application with their SAML attributes.
If it was a traditional authentication with a username/password, once the password matches, you would create a session for them. In this case the password check was done by Microsoft and told your application it was successful by sending the SAML Response to your callback.
If you parse the SAML Response and extract the attributes you can use one of them to create the session. Something persistent such as eduPersonTargetedID which will always be the same value for that user will let you create their session. When they logout and log back in, that eduPersonTargetedID will have the same value in their SAML Response.
SAML Response samples are available here.

Related

Is possible to make login in Azure behind the scenes

I am working on one project in Angular and PHP, I want to make login on Azure using ADAL (Azure Active Directory Library).
It is possible to do that without popup login Microsoft something like pass only username and password or client secret and to get the token for future request?
The way Azure authenticates external websites is through OAuth 2.0 which requires the user to login to their account on the Azure servers and then give your website authorization code so that you can request an access token to complete the OAuth flow.
It isn't secure to capture the user's Username and Password on your website and then send through to Azure, therefore they do not let you do that.
More explanation of the oAuth flow: https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code

How does a SAML IdP communicate changes with the SP?

I'm working to integrate SAML SSO into an older PHP application. I am using simplesamlphp to set up my service provider and for testing purposes, I have a OneLogin dev account set up with a "SAML Test Connector (IdP w/attr)" test application as my IdP. I can successfully sign in, and I can log the user out using single log out. What I'm currently lost with is how the IdP communicates changes such as forced sign out and removing access to the application.
I had assumed that OneLogin would send a request to the URL I provide as the "Single Logout URL" once I forced a user to sign out or removed their privileges to the application along with enough data to identify the user. I would then expire that user's session in the service provider and everything would be good. But OneLogin isn't sending that request like I am expecting (it is only called after I initiate a single logout process on my end). The other option would seem to be me sending requests to OneLogin to validate the session frequently, but that seems inefficient.
What is the proper method for acquiring session/privilege updates from SAML?
From what I read, you don't get updates, you ask IdP about them (request user login or logout, which will check user status):
http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0-cd-02.html#5.3.Single%20Logout%20Profile|outline
I don't think simplesamlphp would act as kind of enforcer of policies, you login as a user, you get your cookie until it expires.
I know you can set up session cookie duration to reasonable value in config.php of simplesamlphp, try that.

How to authorise ADFS users from PHP

I need to allow adfs user to login in php based application.We can integrate SimpleSAMLphp for this purpose but all we need to make Relay Trust Connection through SAML metadata on ADFS server but we can't do that as client don't allow for this. I didn't found any way to authenticate ADFS user by any single api that we pass user credentials and will get ADFS response is user authorised or not?
Even I don't need any user details from ADFS server only to check weather the user is valid or not?
Need more detail.
This works no problem.
Application --> simpleSAMLphp --> ADFS
What does not work?
SAML does "pass user credentials and will get ADFS response is user authenticated or not".
You need to use roles in the SAML assertions to handle authorisation.

auth0 authentication for react-native-ios that communicates with php server

I am creating an react-native-ios app that communicates with a php web app hosted on azure.
How I understand it works:
The user signs up to the app, the server communicates with auth0 server which then returns a JWT token to the php server, saves the token to the database and then sends the token back to the client-device where it is then stored on device.
The user must send the JWT token as a header whenever communicating with the server.
Whenever the user logs out the token is deleted and when signing in, a new JWT must be received.
The user can sign in via using credentials that match what is on the database or sign-in with Google or facebook.
Or is Auth0 just for signing-in with enterprises such as Google or can I use it to sign in to my app also that has login credentials on the database?
I have found the
npm react-native-lock-ios but it doesn't work the way I described above.
In summary, How should I go about this and is what I have explained above correct?
The main problem here is that you did not understand how to work with JWTs. I would advise you to take a deeper look on how this technology works and how Auth0 can help you. But, in summary, this is the workflow for authentication that you must aim:
Your user will choose one of the many identity providers supported by Auth0(e.g. Facebook, Twitter, LinkedIn, SAML, WS Federate and so on).
Your react native app will communicate directly to Auth0 API through the react native lock.
Auth0 will interface with the chosen provider and redirect the user to an authorization page in this provider (case it is needed and it is the first time the user logs in).
Auth0 will generate a JWT and send back to your react native app.
Your react native app will send this JWT to the server (usually on the Authorization HTTP header) when issuing requests to your endpoints.
Your PHP backend will check if this JWT is really valid. This is can be done with Auth0 PHP SDK.
In case the JWT sent has not been tampered (changed irregularly), your backend will accept it as the user identifier and respond the request as expected by your react native app.
As you can see the biggest issue in the approach that you thought you would follow is that the login process does not go through your backend server. It happens on your front-end app (react native) communicating with Auth0 and the identity provider chosen.
JWTs are tokens that hold information (claims) about a subject. These tokens can be validated by anyone that possess a key (public or private). That is, having this key you can validate the token and can rest assured that it has not been changed improperly.
Further more, to answer the question regarding the usage of Auth0 with credentials on your database, you can bet that you can use it. Auth0 provides ways to integrate with your own database to check the existence of a user. This is called a customer user store.
Happy studying.

Server-side Twitter client possible with OAUTH?

Twitter'll phase out HTTP basic authentication by August 2010. In the link my scenarios are from Desktop Applications. Basically my client should tweet new posts on a website.
This would be incredibly simple with HTTP basic auth, because I can store and use my account's username and password in the app to authenticate.
However, with OAUTH I can get final credentials by two means:
Callback method. You are redirected to Twitter, (login if isn't), click allow access, get redirection back to your callback URL.
PIN mode. You get a link to open, (login if isn't), click allow access, receive PIN code. Use this PIN code to authenticate your app.
Do I understand correctly that PIN codes also expire? How is it possible, given a username and password just to tweet from a client application? How can a server side script log in with the username/password and click allow access? All scenarios I could google up are for a web application to authenticate via twitter where the user is in front of the browser to walk through the redirect.
All scenarios I could google up are for a web application to authenticate via twitter where the user is in front of the browser to walk through the redirect.
The user has to be there to authorise you the first time (just as they'd have to provide you a username and password), but the resulting access token does not expire and can be reused (unless the user deauthorises your application, that is).
Store the access token - it's as good as a username/password. Better, actually - if they change their password, your access remains.
The PIN does expire under OAuth 1.0a. Using the verification code returned requires use of the temporary request token in the initial authorization request.
OAuth 2.0 defines more flows - one of which uses a direct login/password mechanism. It's up to Twitter to determine which flows they decide to implement. You can also embed a user-agent in the app.
Desktop apps suffered from a really bad user-experience with OAuth 1.0 which led to 2.0. It's doable, but painful. You can request XAuth access if you need to from Twitter as well. It's almost the same as basic auth.

Categories