react-cas-client
is a simple CAS Client for ReactJS for Apereo CAS server (CAS 2.0 and 3.0 protocol)
npm install react-cas-client
yarn add react-cas-client
import CasClient, { constant } from "react-cas-client";
let casEndpoint;
let casOptions = {};
new CasClient(casEndpoint, casOptions)
.then(successRes => {
console.log(successRes);
// Login user in state / locationStorage ()
// eg. loginUser(response.user);
// Update current path to trim any extra params in url
// eg. this.props.history.replace(response.currentPath);
})
.catch(errorRes => {
console.error(errorRes);
// Error handling
// displayErrorByType(errorRes.type)
// Update current path to trim any extra params in url
// eg. this.props.history.replace(response.currentPath);
});
Endpoint of CAS Server (eg. 'xxxx.casserver.com'
)
path
- CAS server service path (eg. '/cas-tmp'
) (default: '/cas'
)protocol
- CAS server protocol, can be 'http'
, 'https'
) (default: 'https'
);version
- CAS protocol version can be constant.CAS_VERSION_2_0
, constant.CAS_VERSION_3_0
(default: constant.CAS_VERSION_3_0
)validation_proxy_path
- Proxy path for application to make call to CAS server to validate ticket (!! Related to CORS issue !!)constant.CAS_ERROR_FETCH
- Error when validating ticket with CAS Server:constant.CAS_ERROR_PARSE_RESPONSE
- Cannot parse response from CAS serverconstant.CAS_ERROR_AUTH_ERROR
- User is not authorizedUpdate CAS server to set Access-Control-Allow-Origin
for you application
Using reverse proxy in your application, we will use ngnix as example.
*/cas_proxy
to your cas server - https://xxxx.casserver.com/
# nginx.conf
location /cas_proxy {
proxy_pass http://xxxx.casserver.com/;
}
validation_proxy_path
to '/cas_proxy'
npm run test
yarn run test
Author: alancting
Source Code: https://github.com/alancting/react-cas-client
#react #reactjs #javascript