[NEW] CAS authentication (#1116)
This commit is contained in:
parent
6586651610
commit
e351a77a6b
|
@ -82,5 +82,11 @@ export default {
|
||||||
},
|
},
|
||||||
AutoTranslate_Enabled: {
|
AutoTranslate_Enabled: {
|
||||||
type: 'valueAsBoolean'
|
type: 'valueAsBoolean'
|
||||||
|
},
|
||||||
|
CAS_enabled: {
|
||||||
|
type: 'valueAsBoolean'
|
||||||
|
},
|
||||||
|
CAS_login_url: {
|
||||||
|
type: 'valueAsString'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -812,6 +812,10 @@ const RocketChat = {
|
||||||
return 'saml';
|
return 'saml';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (service === 'cas') {
|
||||||
|
return 'cas';
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: remove this after other oauth providers are implemented. e.g. Drupal, github_enterprise
|
// TODO: remove this after other oauth providers are implemented. e.g. Drupal, github_enterprise
|
||||||
const availableOAuth = ['facebook', 'github', 'gitlab', 'google', 'linkedin', 'meteor-developer', 'twitter'];
|
const availableOAuth = ['facebook', 'github', 'gitlab', 'google', 'linkedin', 'meteor-developer', 'twitter'];
|
||||||
return availableOAuth.includes(name) ? 'oauth' : 'not_supported';
|
return availableOAuth.includes(name) ? 'oauth' : 'not_supported';
|
||||||
|
|
|
@ -29,7 +29,7 @@ class AuthenticationWebView extends React.PureComponent {
|
||||||
const authType = navigation.getParam('authType', 'oauth');
|
const authType = navigation.getParam('authType', 'oauth');
|
||||||
return {
|
return {
|
||||||
headerLeft: <CloseModalButton navigation={navigation} />,
|
headerLeft: <CloseModalButton navigation={navigation} />,
|
||||||
title: authType === 'saml' ? 'SSO' : 'OAuth'
|
title: authType === 'saml' || authType === 'cas' ? 'SSO' : 'OAuth'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,15 +72,21 @@ class AuthenticationWebView extends React.PureComponent {
|
||||||
|
|
||||||
onNavigationStateChange = (webViewState) => {
|
onNavigationStateChange = (webViewState) => {
|
||||||
const url = decodeURIComponent(webViewState.url);
|
const url = decodeURIComponent(webViewState.url);
|
||||||
if (this.authType === 'saml') {
|
if (this.authType === 'saml' || this.authType === 'cas') {
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
const ssoToken = navigation.getParam('ssoToken');
|
const ssoToken = navigation.getParam('ssoToken');
|
||||||
if (url.includes('ticket') || url.includes('validate')) {
|
if (url.includes('ticket') || url.includes('validate')) {
|
||||||
const payload = `{ "saml": true, "credentialToken": "${ ssoToken }" }`;
|
let payload;
|
||||||
|
const credentialToken = { credentialToken: ssoToken };
|
||||||
|
if (this.authType === 'saml') {
|
||||||
|
payload = { ...credentialToken, saml: true };
|
||||||
|
} else {
|
||||||
|
payload = { cas: credentialToken };
|
||||||
|
}
|
||||||
// We need to set a timeout when the login is done with SSO in order to make it work on our side.
|
// We need to set a timeout when the login is done with SSO in order to make it work on our side.
|
||||||
// It is actually due to the SSO server processing the response.
|
// It is actually due to the SSO server processing the response.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.login(JSON.parse(payload));
|
this.login(payload);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,9 @@ class LoginSignupView extends React.Component {
|
||||||
server: PropTypes.string,
|
server: PropTypes.string,
|
||||||
services: PropTypes.object,
|
services: PropTypes.object,
|
||||||
Site_Name: PropTypes.string,
|
Site_Name: PropTypes.string,
|
||||||
Gitlab_URL: PropTypes.string
|
Gitlab_URL: PropTypes.string,
|
||||||
|
CAS_enabled: PropTypes.bool,
|
||||||
|
CAS_login_url: PropTypes.string
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -242,6 +244,13 @@ class LoginSignupView extends React.Component {
|
||||||
this.openOAuth({ url, ssoToken, authType: 'saml' });
|
this.openOAuth({ url, ssoToken, authType: 'saml' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onPressCas = () => {
|
||||||
|
const { server, CAS_login_url } = this.props;
|
||||||
|
const ssoToken = random(17);
|
||||||
|
const url = `${ CAS_login_url }/?service=${ server }/_cas/${ ssoToken }`;
|
||||||
|
this.openOAuth({ url, ssoToken, authType: 'cas' });
|
||||||
|
}
|
||||||
|
|
||||||
getOAuthState = () => {
|
getOAuthState = () => {
|
||||||
const credentialToken = random(43);
|
const credentialToken = random(43);
|
||||||
return Base64.encodeURI(JSON.stringify({ loginStyle: 'popup', credentialToken, isCordova: true }));
|
return Base64.encodeURI(JSON.stringify({ loginStyle: 'popup', credentialToken, isCordova: true }));
|
||||||
|
@ -341,12 +350,17 @@ class LoginSignupView extends React.Component {
|
||||||
onPress = () => this.onPressSaml(service);
|
onPress = () => this.onPressSaml(service);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'cas': {
|
||||||
|
onPress = () => this.onPressCas();
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
name = name.charAt(0).toUpperCase() + name.slice(1);
|
name = name.charAt(0).toUpperCase() + name.slice(1);
|
||||||
|
const { CAS_enabled } = this.props;
|
||||||
let buttonText;
|
let buttonText;
|
||||||
if (service.service === 'saml') {
|
if (service.service === 'saml' || (service.service === 'cas' && CAS_enabled)) {
|
||||||
buttonText = <Text style={styles.serviceName}>{name}</Text>;
|
buttonText = <Text style={styles.serviceName}>{name}</Text>;
|
||||||
} else {
|
} else {
|
||||||
buttonText = (
|
buttonText = (
|
||||||
|
@ -418,6 +432,8 @@ const mapStateToProps = state => ({
|
||||||
server: state.server.server,
|
server: state.server.server,
|
||||||
Site_Name: state.settings.Site_Name,
|
Site_Name: state.settings.Site_Name,
|
||||||
Gitlab_URL: state.settings.API_Gitlab_URL,
|
Gitlab_URL: state.settings.API_Gitlab_URL,
|
||||||
|
CAS_enabled: state.settings.CAS_enabled,
|
||||||
|
CAS_login_url: state.settings.CAS_login_url,
|
||||||
services: state.login.services
|
services: state.login.services
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue