Skip to content

Commit

Permalink
Merge 9a5b882 into 3ca6691
Browse files Browse the repository at this point in the history
  • Loading branch information
alancting committed Sep 15, 2020
2 parents 3ca6691 + 9a5b882 commit 0969c2f
Showing 1 changed file with 55 additions and 10 deletions.
65 changes: 55 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,34 @@ yarn add react-cas-client

## Usage

### Initialize CAS Client

```javascript
import CasClient, { constant } from "react-cas-client";

let casEndpoint;
let casOptions = {};

new CasClient(casEndpoint, casOptions)
let casClient = new CasClient(casEndpoint, casOptions);
```

#### CAS Endpoint

Endpoint of CAS Server (eg. `'xxxx.casserver.com'`)

#### CAS Options

- `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 !!**)

### Start authorization flow (Login)

```javascript
// Basic usage
casClient
.auth()
.then(successRes => {
console.log(successRes);
// Login user in state / locationStorage ()
Expand All @@ -47,25 +68,49 @@ new CasClient(casEndpoint, casOptions)
// Update current path to trim any extra params in url
// eg. this.props.history.replace(response.currentPath);
});
```

### CAS Endpoint:
// If you want to use as gateway
let gateway = true;

Endpoint of CAS Server (eg. `'xxxx.casserver.com'`)
casClient
.auth(gateway)
.then(successRes => {})
.catch(errorRes => {});
```

### CAS Options
#### Gateway

- `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 !!**)
Apply gateway param to CAS login url when `gateway` is given ([Documentation](https://apereo.github.io/cas/6.0.x/protocol/CAS-Protocol-V2-Specification.html#211-parameters))

- Boolean: `true` / `false` (default: `false`)

### Possible Error Types
#### Possible Error Types

- `constant.CAS_ERROR_FETCH` - Error when validating ticket with CAS Server:
- `constant.CAS_ERROR_PARSE_RESPONSE` - Cannot parse response from CAS server
- `constant.CAS_ERROR_AUTH_ERROR` - User is not authorized

### Logout CAS

```javascript
// Assume current url is https://localhost.com/

// Basic usage
casClient.logout(redirectPath);

// If you want to apply redirect url to CAS logout url
// You can applied redirectPath.
// In this case, https://localhost.com/logout will be applied to logout url
let redirectPath = "/logout";
casClient.logout(redirectPath);
```

#### Redirect Path

Apply redirect url to CAS logout url when `refirectPath` is given ([Documentation](https://apereo.github.io/cas/6.0.x/protocol/CAS-Protocol-V2-Specification.html#211-parameters))

- String: any path (default: `/`)

## CORS Issue

### Option 1
Expand Down

0 comments on commit 0969c2f

Please sign in to comment.