Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I use SAML login with a REST API + SPA app?

Tags:

rest

saml

I want to use SAML login for a single web application with a REST API. How should I do this? Usually, say with OAuth, lets use Google/Firebase as an example:

  • SPA calls Google to login. Google returns a Google ID token
  • SPA can call Server with Google ID token which server can verify with Google and return an access token for use with the application

Firstly is this correct or did I get something wrong so far?


But with SAML, from what I can see, its user is redirected to SAML IDP, SAML IDP then redirects user to a server assertion URL. Because there is this redirect, how do I use it in the context of REST? I am unfamiliar with SAML, but I dont see a token. The server just gets an "assertion" with the user information?

like image 426
Jiew Meng Avatar asked May 01 '19 03:05

Jiew Meng


People also ask

Can SAML be used for REST API?

All clients follow a basic message flow to access the REST API using SAML. Whereas CSM acts as both the service provider and the identity provider in OAuth2 protocol, SAML protocol introduces a third-party identity provider.

Does SAML work for mobile apps?

SAML was simply not designed for modern application types, such as SPAs and mobile apps. You'll spend time fighting the protocol and still end up with a solution that is cumbersome and has security holes. Instead, we recommend using OpenID Connect in SPAs and mobile applications.

How do I authenticate using SAML?

SAML uses a claims-based authentication workflow. First, when a user tries to access a site, the service provider asks the identity provider to authenticate the user. Then, the service provider uses the SAML assertion issued by the identity provider to grant the user access.

How SAML is implemented in application?

Go to Identity Provider -> Click on Add Provider -> Select SAML list from there -> Enter details such as Provider Name, Provider's Entity ID, Provider's SSO URL, Certificate (used for token signing). Go to Service Provider -> Provide Entity Id (that verifies your application).


1 Answers

Here is the sequence of events which happen when the application is using SAML for the authentication:

  1. server should send a response to the client with the URL to SAML IDP.
  2. client application redirects the browser to SAML IDP (1).
  3. After successful authentication, SAML server sends response with the redirect back to the client. The browser automatically posts the HTML form SAML server to your server.
  4. After validating SAML assert and successful authorization (you can use user's information or other attributes to authorize the user to use your application), your server should generate a token that now can be used by the client application.

This is a basic scenario.

See spirng-saml project here, you can try and play with the sample web application. https://projects.spring.io/spring-security-saml

like image 164
user1206747 Avatar answered Oct 14 '22 06:10

user1206747