casdoor-react-sdk
Version:
React client SDK for Casdoor
64 lines (63 loc) • 2.26 kB
JavaScript
;
// Copyright 2022 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.AuthCallback = void 0;
const React = require("react");
class AuthCallback extends React.Component {
constructor() {
super(...arguments);
this.signin = () => {
const { sdk, serverUrl, isGetTokenSuccessful, saveTokenFromResponse } = this.props;
sdk.signin(serverUrl).then((res) => {
if (isGetTokenSuccessful(res)) {
if (window !== window.parent) {
this.sendSuccessfulLoginMessage();
}
if (saveTokenFromResponse) {
saveTokenFromResponse(res);
}
}
else {
if (window !== window.parent) {
this.sendLoginFailureMessage();
}
}
});
};
this.sendSuccessfulLoginMessage = () => {
const message = {
tag: "Casdoor",
type: "SilentSignin",
data: "success",
};
window.parent.postMessage(message, "*");
};
this.sendLoginFailureMessage = () => {
const message = {
tag: "Casdoor",
type: "SilentSignin",
data: "login-failure",
};
window.parent.postMessage(message, "*");
};
}
UNSAFE_componentWillMount() {
this.signin();
}
render() {
return React.createElement(React.Fragment, null);
}
}
exports.AuthCallback = AuthCallback;