Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CAS authentication of a RESTful web service

My application needs to access a RESTful web service running on a different server. This web service uses CAS authentication, and when consuming it through the browser it will redirect to CAS login if the user isn't already authenticated. There is no method to actually login through CAS. My application also uses CAS so users will be authenticated

I'd like to access it through JQuery/Ajax, but the server doesn't seem to be configured for JSONP which I understand is essential because of the cross-domain issue.

Now, I could make the Ajax requests via my server instead, which leads to my question: with no CAS login method for my server to call, how can I 'tell' the web service that the user is authenticated?

So I suppose firstly I want to get clear on what's going on between the browser, CAS, and the RESTful service, and how authorisation is handled without any explict passing of credentials. Secondly, I want to see how/if I can replicate that when calling the service from my server- it wouldn't be the same session as a request from the browser so there'd be no CAS authorisation token, but I don't see how to get one or provide it.

like image 715
user814425 Avatar asked Nov 27 '12 10:11

user814425


People also ask

How do I authenticate a restful web service?

Use of basic authentication is specified as follows: The string "Basic " is added to the Authorization header of the request. The username and password are combined into a string with the format "username:password", which is then base64 encoded and added to the Authorization header of the request.

What is authentication in restful API?

Basic authentication is an HTTP-based authentication approach and is the simplest way to secure REST APIs. It uses a Base64 format to encode usernames and passwords, both of which are stored in the HTTP header.

How does basic authentication work REST API?

Users of the REST API can authenticate by providing their user ID and password within an HTTP header. To use this method of authentication with HTTP methods, such as POST, PATCH, and DELETE, the ibm-mq-rest-csrf-token HTTP header must also be provided, as well as a user ID and password.


2 Answers

For question 1 on how the authentication/single sign on works:
When you login the CAS server (say security.example.com) would set a cookie in your browser for the domain security.example.com. A typical flow when you access secured files through the browser on an application using standard CAS authentication and validation filters looks like:

  1. CAS Authentication filter configured for the application checks if user object is in session. If yes user is let through
  2. If not, CAS Authentication filter redirects browser to CAS login page. In a single sign on scenario, CAS server recognizes its own cookie, checks if the application is registered and participating in single sign on - if yes redirects browser back to the application with a service ticket.
  3. CAS validation filter configured on the application identifies the service ticket and contacts CAS Server for validating the ticket and creating assertion object

For this entire flow to work you need cookies and session handling to work.

For question 2 on how to handle authentication on the server side:
We had a similar problem in our application and use 2 different ways to get around it:

  1. Use an internal system user and do a server to server access passing the credentials of this user using basic authentication headers. Of course you need to have appropriate filters configured to handle a non-interactive login with basic authentication tokens. This is easy to implement however has obvious downsides like having this special system user, your application seeing the users password etc.
  2. Use proxy authentication. In this approach when your user is authenticated for application1, it also generates a proxy ticket to be used by application2 (server to server call). This proxy ticket can be passed in server to server communication so that application1 accesses application2 on behalf of the user
like image 141
6ton Avatar answered Sep 29 '22 01:09

6ton


Im using such a setup in one of my projects. Some of the CAS implementations enable authorization through a rest call. Try adding a basic authorization header(Base 64 Encoding of Username and Password). it looks something like this

Header("Authorization","Basic ")

Also try to access the REST API using REST Client on Mozilla for debugging purposes. It will really help you to understand the various headers etc.

like image 38
dhiresh mehta Avatar answered Sep 29 '22 00:09

dhiresh mehta