Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/casdoor/casdoor-nodejs-sdk
Node.js client SDK for Casdoor, see example at: https://github.com/casdoor/casdoor-nodejs-react-example
https://github.com/casdoor/casdoor-nodejs-sdk
casdoor javascript nodejs sdk sso
Last synced: 7 days ago
JSON representation
Node.js client SDK for Casdoor, see example at: https://github.com/casdoor/casdoor-nodejs-react-example
- Host: GitHub
- URL: https://github.com/casdoor/casdoor-nodejs-sdk
- Owner: casdoor
- License: apache-2.0
- Created: 2021-07-05T17:44:52.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-18T16:40:30.000Z (3 months ago)
- Last Synced: 2025-01-14T08:09:01.691Z (15 days ago)
- Topics: casdoor, javascript, nodejs, sdk, sso
- Language: TypeScript
- Homepage: https://github.com/casdoor/casdoor
- Size: 803 KB
- Stars: 13
- Watchers: 3
- Forks: 25
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# casdoor-nodejs-sdk
[![GitHub Actions](https://github.com/casdoor/casdoor-nodejs-sdk/actions/workflows/semantic-release.yml/badge.svg)](https://github.com/casdoor/casdoor-nodejs-sdk/actions)
[![codebeat badge](https://codebeat.co/badges/4f1d141f-047a-43fe-a5d0-889fa4aaf726)](https://codebeat.co/projects/github-com-casdoor-casdoor-nodejs-sdk-master)
[![NPM version][npm-image]][npm-url]
[![NPM download][download-image]][download-url]
[![Release](https://img.shields.io/github/release/casdoor/casdoor-nodejs-sdk.svg)](https://github.com/casdoor/casdoor-nodejs-sdk/releases/latest)
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/5rPsrAzK7S)[npm-image]: https://img.shields.io/npm/v/casdoor-nodejs-sdk.svg?style=flat-square
[npm-url]: https://npmjs.com/package/casdoor-nodejs-sdk
[download-image]: https://img.shields.io/npm/dm/casdoor-nodejs-sdk.svg?style=flat-square
[download-url]: https://npmjs.com/package/casdoor-nodejs-sdkThis is Casdoor's SDK for NodeJS will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch.
Casdoor SDK is very simple to use. We will show you the steps below.
## Examples
The following examples use Node.js Express as backend, but have different frontend frameworks. Choose the appropriate example based on your tech stack:
1. React frontend: https://github.com/casdoor/casdoor-nodejs-react-example
2. Angular frontend: https://github.com/casdoor/casdoor-nodejs-angular-example## Installation
```shell script
# NPM
npm i casdoor-nodejs-sdk# Yarn
yarn add casdoor-nodejs-sdk
```## Step1. Init SDK
Initialization requires 5 parameters, which are all string type:
| Name (in order) | Must | Description |
|-----------------|------|-----------------------------------------------------|
| endpoint | Yes | Casdoor Server Url, such as `http://localhost:8000` |
| clientId | Yes | Client ID for the Casdoor application |
| clientSecret | Yes | Client secret for the Casdoor application |
| certificate | Yes | x509 certificate content of Application.cert |
| orgName | Yes | The name for the Casdoor organization |
| appName | No | The name for the Casdoor application |```typescript
import { SDK, Config } from 'casdoor-nodejs-sdk'
import type { AxiosRequestConfig } from 'axios';
import https from 'node:https';// Optional param for providing a self-signed CA with requests.
const axiosConfig: AxiosRequestConfig = {
httpsAgent: new https.Agent({ ca: ... })
}const authCfg: Config = {
endpoint: '',
clientId: '',
clientSecret: '',
certificate: '',
orgName: '',
}const sdk = new SDK(authCfg)
// or
const sdk = new SDK(authCfg, axiosConfig)// call sdk to handle
```## Step2. Get service and use
```typescript
// user
const { data: users } = await sdk.getUsers()// auth
const token = await sdk.getAuthToken('')
const user = sdk.parseJwtToken(token)
```