title: Using JWT to authorize REST API requests after SAML Authentication
body: <p>I'm struggling theese days on the possible way to configure an Authentication + authorization system to consume a REST API from a mobile application.</p>
  
  <p>Scenario:
  We've developed 3 independent portals for a big customer that serves several users. 
  To enable a SSO for the 3 portals we've implemented a SAML authentication system using SimpleSAMLphp.
  Every portal has a service provider and they make assertion requests against a central IdP.
  The IdP checks username and password against a database where passwords are hashed and stored during registration.
  After the login, the authorization on the portals is handled by the session on the server, and so far everything was fine.</p>
  
  <p>Now the customer asked us to develop a mobile application that will require the users to login and access several of their protected resources collected during the usage of the 3 portals.</p>
  
  <p>We've decided to develop a frontend application using ionic that will consume a REST API made in node.js that will serve all the data (both protected and unprotected resources).</p>
  
  <p>Now here comes the question: to authorize access to protected resources on the Api we'd like to use JWT to easily achieve a stateless system.
  The doubt is how to perform the authentication? We've the opportunity to check the credentials directly against the database skipping the SAML process, otherwise we've to implement a solution where the SSO IdP acts as authentication provider and then when an attempt is successful the API app will get the response from the idp and then issue a signed jwt to the consumer client. Is this second way a common implementation? Is it possible? </p>
  
  <p>What path do you suggest to follow? The first could be very easy to achieve, but since we're using html+js for the app's frontend, if we decide to use the second solution probably in the near future we could recycle some code from the app to modernize some functions on the web portals, maintaining the jwt pattern and consuming the new Api also on the web.
  I believe that in this case will be easier to ask a token to the new api using  someway the logged in user's data already in the session of the portal. Sounds possible? </p>
  
  <p>I hope that everything was clear, any help will be appreciated!</p>
  
  <p>Thanks </p>