[FIX] Make SAML to work on Rocket.Chat < 2.3.0 (#1629)
This commit is contained in:
parent
862ffa13c6
commit
ba27c580f4
|
@ -11,7 +11,7 @@ import StatusBar from '../containers/StatusBar';
|
||||||
import ActivityIndicator from '../containers/ActivityIndicator';
|
import ActivityIndicator from '../containers/ActivityIndicator';
|
||||||
import { withTheme } from '../theme';
|
import { withTheme } from '../theme';
|
||||||
import { themedHeader } from '../utils/navigation';
|
import { themedHeader } from '../utils/navigation';
|
||||||
import log from '../utils/log';
|
import debounce from '../utils/debounce';
|
||||||
|
|
||||||
const userAgent = isIOS
|
const userAgent = isIOS
|
||||||
? 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
|
? 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
|
||||||
|
@ -43,6 +43,12 @@ class AuthenticationWebView extends React.PureComponent {
|
||||||
this.redirectRegex = new RegExp(`(?=.*(${ props.server }))(?=.*(credentialToken))(?=.*(credentialSecret))`, 'g');
|
this.redirectRegex = new RegExp(`(?=.*(${ props.server }))(?=.*(credentialToken))(?=.*(credentialSecret))`, 'g');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
if (this.debouncedLogin && this.debouncedLogin.stop) {
|
||||||
|
this.debouncedLogin.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dismiss = () => {
|
dismiss = () => {
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
navigation.pop();
|
navigation.pop();
|
||||||
|
@ -65,44 +71,34 @@ class AuthenticationWebView extends React.PureComponent {
|
||||||
this.dismiss();
|
this.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line react/sort-comp
|
||||||
|
debouncedLogin = debounce(params => this.login(params), 3000);
|
||||||
|
|
||||||
onNavigationStateChange = (webViewState) => {
|
onNavigationStateChange = (webViewState) => {
|
||||||
try {
|
const url = decodeURIComponent(webViewState.url);
|
||||||
const url = decodeURIComponent(webViewState.url);
|
if (this.authType === 'saml' || this.authType === 'cas') {
|
||||||
|
const { navigation } = this.props;
|
||||||
if (this.authType === 'cas') {
|
const ssoToken = navigation.getParam('ssoToken');
|
||||||
const { navigation } = this.props;
|
if (url.includes('ticket') || url.includes('validate') || url.includes('saml_idp_credentialToken')) {
|
||||||
const ssoToken = navigation.getParam('ssoToken');
|
let payload;
|
||||||
if (url.includes('ticket') || url.includes('validate')) {
|
if (this.authType === 'saml') {
|
||||||
const payload = { cas: { credentialToken: ssoToken } };
|
const parsedUrl = parse(url, true);
|
||||||
// We need to set a timeout when the login is done with SSO in order to make it work on our side.
|
const token = (parsedUrl.query && parsedUrl.query.saml_idp_credentialToken) || ssoToken;
|
||||||
// It is actually due to the SSO server processing the response.
|
const credentialToken = { credentialToken: token };
|
||||||
setTimeout(() => {
|
payload = { ...credentialToken, saml: true };
|
||||||
this.login(payload);
|
} else {
|
||||||
}, 3000);
|
payload = { cas: { credentialToken: ssoToken } };
|
||||||
}
|
}
|
||||||
|
this.debouncedLogin(payload);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.authType === 'saml') {
|
if (this.authType === 'oauth') {
|
||||||
const parsedUrl = parse(url, true);
|
if (this.redirectRegex.test(url)) {
|
||||||
if (parsedUrl.query && parsedUrl.query.saml_idp_credentialToken) {
|
const parts = url.split('#');
|
||||||
const payload = { credentialToken: parsedUrl.query.saml_idp_credentialToken, saml: true };
|
const credentials = JSON.parse(parts[1]);
|
||||||
// We need to set a timeout when the login is done with SSO in order to make it work on our side.
|
this.login({ oauth: { ...credentials } });
|
||||||
// It is actually due to the SSO server processing the response.
|
|
||||||
setTimeout(() => {
|
|
||||||
this.login(payload);
|
|
||||||
}, 3000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.authType === 'oauth') {
|
|
||||||
if (this.redirectRegex.test(url)) {
|
|
||||||
const parts = url.split('#');
|
|
||||||
const credentials = JSON.parse(parts[1]);
|
|
||||||
this.login({ oauth: { ...credentials } });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
log(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -250,8 +250,9 @@ class LoginSignupView extends React.Component {
|
||||||
const { server } = this.props;
|
const { server } = this.props;
|
||||||
const { clientConfig } = loginService;
|
const { clientConfig } = loginService;
|
||||||
const { provider } = clientConfig;
|
const { provider } = clientConfig;
|
||||||
const url = `${ server }/_saml/authorize/${ provider }/`;
|
const ssoToken = random(17);
|
||||||
this.openOAuth({ url, authType: 'saml' });
|
const url = `${ server }/_saml/authorize/${ provider }/${ ssoToken }`;
|
||||||
|
this.openOAuth({ url, ssoToken, authType: 'saml' });
|
||||||
}
|
}
|
||||||
|
|
||||||
onPressCas = () => {
|
onPressCas = () => {
|
||||||
|
|
Loading…
Reference in New Issue