GithubHelp home page GithubHelp logo

morellon / cas-rest-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robertokl/cas-rest-client

1.0 1.0 1.0 98 KB

A RestClient for integrating with applications protected by CAS Single-Sign-On (http://www.jasig.org/cas)

Ruby 100.00%

cas-rest-client's Introduction

CasRestClient

A simple HTTP and REST client to interact with services using CAS for authentication. Strongly based on RestClient.

Basic Usage:

The simplest usage is to create an instance of CasRestClient with the credentials for your app and use it every time you need to interact with the cas-protected application.

require 'rubygems'
require 'cas_rest_client'

client = CasRestClient.new :uri => 'https://some-cas-server.com/tickets', :username => 'user', password => 'pass'

client.post 'http://service.using.cas', some_xml, :content_type => :xml

When the CasRestClient instance is created it'll automatically create a Ticket-Granting Ticket (tgt) and use it during its lifetime. If the credentials provided are not valid, a RestClient::Request::Unauthorized exception will be raised.

Passing custom parameters to CAS

You can pass any custom parameter by adding it to the initialization hash. Doing so, CasRestClient will use these parameters to create the Ticket-Granting Ticket on CAS.

For example, to pass a 'domain' custom parameter just add:

client = CasRestClient.new :uri => 'https://some-cas-server.com/tickets', :username => 'user', password => 'pass', :domain => "myDomain"

client.post 'http://service.using.cas', some_xml, :content_type => :xml

Custom parameters for the cas-protected app

Since CasRestClient uses RestClient to make HTTP requests, you can set any parameters that RestClient accepts while interacting with the cas-protected application.

For example, to pass additional HTTP headers:

client = CasRestClient.new :uri => 'https://some-cas-server.com/tickets', :username => 'user', password => 'pass'

headers = {:content_type => 'text/xml', :user_agent => 'my_app', 'Accept-Language' => 'en_US'}
client.post 'http://service.using.cas', some_xml, headers

Additional options

:service => 'some_string' (default to cas-protected app URI)

By default, CasRestClient uses the URI of the cas-protected app as the service parameter to create service tickets. To change this just provide the :service param:

client = CasRestClient.new :uri => 'https://some-cas-server.com/tickets', :service => "http://my_svc.com"

client.post 'http://service.using.cas', some_xml, headers

With this example configuration, CasRestClient will always create service tickets for the http://my_svc.com service.

use_cookie => Boolean (default true)

By default, the first time you make a request to the cas-protected app CasRestClient will save all cookies from the response and give it back in all other requests. This prevents 2 extra requests for every single request: your application won't need to ask CAS for a new service ticket and the cas-protected app won't need to check if the ticket is valid.

If you want to prevent this behaviour, just set :use_cookies to false:

client = CasRestClient.new :uri => 'https://some-cas-server.com/tickets', :use_cookies => false

client.post 'http://service.using.cas', some_xml, headers

Project info

Written by Antonio Marques and Roberto Klein. Contributions and feedback are welcomed.

cas-rest-client's People

Contributors

acmarques avatar robertokl avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.