UNPKG

casdoor-nodejs-sdk

Version:
47 lines (46 loc) 1.87 kB
"use strict"; // Copyright 2021 The Casdoor Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.UrlSDK = void 0; class UrlSDK { constructor(config) { this.config = config; } getSignUrl(action, redirectUri) { const scope = 'read'; const state = this.config.appName; return `${this.config.endpoint}/${action}/oauth/authorize?client_id=${this.config.clientId}&response_type=code&redirect_uri=${redirectUri.split(/[?#]/)[0]}&scope=${scope}&state=${state}`; } getSignUpUrl(enablePassword, redirectUri) { if (enablePassword) { return `${this.config.endpoint}/signup/${this.config.appName}`; } else { return this.getSignUrl('signup', redirectUri); } } getSignInUrl(redirectUri) { return this.getSignUrl('login', redirectUri); } getUserProfileUrl(userName, accessToken) { const param = accessToken ? `?access_token=${accessToken}` : ''; return `${this.config.endpoint}/users/${this.config.orgName}/${userName}${param}`; } getMyProfileUrl(accessToken) { const param = accessToken ? `?access_token=${accessToken}` : ''; return `${this.config.endpoint}/account${param}`; } } exports.UrlSDK = UrlSDK;