forked from Ivasoft/mattermost-mobile
MM_36205 : Code clean up
This commit is contained in:
12
app/constants/authentication.ts
Normal file
12
app/constants/authentication.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import keyMirror from '@utils/key_mirror';
|
||||
|
||||
export default keyMirror({
|
||||
GITLAB: null,
|
||||
GOOGLE: null,
|
||||
OFFICE365: null,
|
||||
OPENID: null,
|
||||
SAML: null,
|
||||
});
|
||||
@@ -2,6 +2,7 @@
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import Attachment from './attachment';
|
||||
import Authentication from './authentication';
|
||||
import Database from './database';
|
||||
import DeepLink from './deep_linking';
|
||||
import Device from './device';
|
||||
@@ -16,6 +17,7 @@ import WebsocketEvents from './websocket';
|
||||
|
||||
export {
|
||||
Attachment,
|
||||
Authentication,
|
||||
Database,
|
||||
DeepLink,
|
||||
Device,
|
||||
|
||||
@@ -76,12 +76,6 @@ const ViewTypes = keyMirror({
|
||||
|
||||
REMOVE_LAST_CHANNEL_FOR_TEAM: null,
|
||||
|
||||
GITLAB: null,
|
||||
GOOGLE: null,
|
||||
OFFICE365: null,
|
||||
OPENID: null,
|
||||
SAML: null,
|
||||
|
||||
SET_INITIAL_POST_VISIBILITY: null,
|
||||
RECEIVED_FOCUSED_POST: null,
|
||||
LOADING_POSTS: null,
|
||||
|
||||
@@ -37,23 +37,6 @@ const withIntl = (Screen: React.ComponentType) => {
|
||||
}
|
||||
}
|
||||
|
||||
const withDatabaseProvider = async (Screens: React.ComponentType) => {
|
||||
|
||||
const databaseClient = new DatabaseManager()
|
||||
const serverDatabase = await databaseClient.getActiveServerDatabase();
|
||||
|
||||
if(!serverDatabase){
|
||||
// server database has not been set yet
|
||||
return (<Screens/>);
|
||||
}
|
||||
return (
|
||||
<DatabaseProvider database={serverDatabase}>
|
||||
<Screens/>
|
||||
</DatabaseProvider>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Navigation.setLazyComponentRegistrator((screenName) => {
|
||||
let screen: any|undefined;
|
||||
let extraStyles: StyleProp<ViewStyle>;
|
||||
|
||||
@@ -6,7 +6,7 @@ import {Image, Text} from 'react-native';
|
||||
import Button from 'react-native-button';
|
||||
|
||||
import LocalConfig from '@assets/config.json';
|
||||
import ViewTypes from '@constants/view';
|
||||
import {Authentication} from '@constants';
|
||||
import {makeStyleSheetFromTheme} from '@utils/theme';
|
||||
|
||||
const GitLabOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => {
|
||||
@@ -14,7 +14,7 @@ const GitLabOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => {
|
||||
const forceHideFromLocal = LocalConfig.HideGitLabLoginExperimental;
|
||||
|
||||
const handlePress = () => {
|
||||
onPress(ViewTypes.GITLAB);
|
||||
onPress(Authentication.GITLAB);
|
||||
};
|
||||
|
||||
if (!forceHideFromLocal && config.EnableSignUpWithGitLab === 'true') {
|
||||
|
||||
@@ -6,14 +6,14 @@ import {Image} from 'react-native';
|
||||
import Button from 'react-native-button';
|
||||
|
||||
import FormattedText from '@components/formatted_text';
|
||||
import ViewTypes from '@constants/view';
|
||||
import {Authentication} from '@constants';
|
||||
import {makeStyleSheetFromTheme} from '@utils/theme';
|
||||
|
||||
const GoogleOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => {
|
||||
const styles = getStyleSheet(theme);
|
||||
|
||||
const handlePress = () => {
|
||||
onPress(ViewTypes.GOOGLE);
|
||||
onPress(Authentication.GOOGLE);
|
||||
};
|
||||
|
||||
if (config.EnableSignUpWithGoogle === 'true') {
|
||||
|
||||
@@ -6,7 +6,7 @@ import Button from 'react-native-button';
|
||||
|
||||
import LocalConfig from '@assets/config.json';
|
||||
import FormattedText from '@components/formatted_text';
|
||||
import ViewTypes from '@constants/view';
|
||||
import {Authentication} from '@constants';
|
||||
import {makeStyleSheetFromTheme} from '@utils/theme';
|
||||
|
||||
const Office365Option = ({config, license, onPress, theme}: LoginOptionWithConfigAndLicenseProps) => {
|
||||
@@ -16,7 +16,7 @@ const Office365Option = ({config, license, onPress, theme}: LoginOptionWithConfi
|
||||
license.Office365OAuth === 'true';
|
||||
|
||||
const handlePress = () => {
|
||||
onPress(ViewTypes.OFFICE365);
|
||||
onPress(Authentication.OFFICE365);
|
||||
};
|
||||
|
||||
if (!forceHideFromLocal && o365Enabled) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import React from 'react';
|
||||
import Button from 'react-native-button';
|
||||
|
||||
import FormattedText from '@components/formatted_text';
|
||||
import ViewTypes from '@constants/view';
|
||||
import {Authentication} from '@constants';
|
||||
import {isMinimumServerVersion} from '@utils/helpers';
|
||||
import {makeStyleSheetFromTheme} from '@utils/theme';
|
||||
|
||||
@@ -14,7 +14,7 @@ const OpenIdOption = ({config, license, onPress, theme}: LoginOptionWithConfigAn
|
||||
const openIdEnabled = config.EnableSignUpWithOpenId === 'true' && license.IsLicensed === 'true' && isMinimumServerVersion(config.Version, 5, 33, 0);
|
||||
|
||||
const handlePress = () => {
|
||||
onPress(ViewTypes.OPENID);
|
||||
onPress(Authentication.OPENID);
|
||||
};
|
||||
|
||||
if (openIdEnabled) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {Text} from 'react-native';
|
||||
import Button from 'react-native-button';
|
||||
|
||||
import LocalConfig from '@assets/config.json';
|
||||
import ViewTypes from '@constants/view';
|
||||
import {Authentication} from '@constants';
|
||||
import {makeStyleSheetFromTheme} from '@utils/theme';
|
||||
|
||||
const SamlOption = ({config, license, onPress, theme}: LoginOptionWithConfigAndLicenseProps) => {
|
||||
@@ -15,7 +15,7 @@ const SamlOption = ({config, license, onPress, theme}: LoginOptionWithConfigAndL
|
||||
const enabled = config.EnableSaml === 'true' && license.IsLicensed === 'true' && license.SAML === 'true';
|
||||
|
||||
const handlePress = () => {
|
||||
onPress(ViewTypes.SAML);
|
||||
onPress(Authentication.SAML);
|
||||
};
|
||||
|
||||
if (!forceHideFromLocal && enabled) {
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Client4} from '@client/rest';
|
||||
import ViewTypes from '@constants/view';
|
||||
import emmProvider from '@init/emm_provider';
|
||||
import React from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
|
||||
import {Client4} from '@client/rest';
|
||||
import {Authentication} from '@constants';
|
||||
import {useManagedConfig} from '@mattermost/react-native-emm';
|
||||
import {scheduleExpiredNotification} from '@requests/remote/push_notification';
|
||||
import {ssoLogin} from '@requests/remote/user';
|
||||
|
||||
import {resetToChannel} from '@screens/navigation';
|
||||
import {ErrorApi} from '@typings/api/client4';
|
||||
import {isMinimumServerVersion} from '@utils/helpers';
|
||||
import React from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
|
||||
import SSOWithRedirectURL from './sso_with_redirect_url';
|
||||
import SSOWithWebView from './sso_with_webview';
|
||||
@@ -27,31 +26,33 @@ interface SSOProps {
|
||||
|
||||
const SSO = ({config, serverUrl, ssoType, theme}: SSOProps) => {
|
||||
const intl = useIntl();
|
||||
const managedConfig = useManagedConfig();
|
||||
|
||||
const [loginError, setLoginError] = React.useState<string>('');
|
||||
let completeUrlPath = '';
|
||||
let loginUrl = '';
|
||||
switch (ssoType) {
|
||||
case ViewTypes.GOOGLE: {
|
||||
case Authentication.GOOGLE: {
|
||||
completeUrlPath = '/signup/google/complete';
|
||||
loginUrl = `${serverUrl}/oauth/google/mobile_login`;
|
||||
break;
|
||||
}
|
||||
case ViewTypes.GITLAB: {
|
||||
case Authentication.GITLAB: {
|
||||
completeUrlPath = '/signup/gitlab/complete';
|
||||
loginUrl = `${serverUrl}/oauth/gitlab/mobile_login`;
|
||||
break;
|
||||
}
|
||||
case ViewTypes.SAML: {
|
||||
case Authentication.SAML: {
|
||||
completeUrlPath = '/login/sso/saml';
|
||||
loginUrl = `${serverUrl}/login/sso/saml?action=mobile`;
|
||||
break;
|
||||
}
|
||||
case ViewTypes.OFFICE365: {
|
||||
case Authentication.OFFICE365: {
|
||||
completeUrlPath = '/signup/office365/complete';
|
||||
loginUrl = `${serverUrl}/oauth/office365/mobile_login`;
|
||||
break;
|
||||
}
|
||||
case ViewTypes.OPENID: {
|
||||
case Authentication.OPENID: {
|
||||
completeUrlPath = '/signup/openid/complete';
|
||||
loginUrl = `${serverUrl}/oauth/openid/mobile_login`;
|
||||
break;
|
||||
@@ -104,8 +105,8 @@ const SSO = ({config, serverUrl, ssoType, theme}: SSOProps) => {
|
||||
theme,
|
||||
};
|
||||
|
||||
//fixme: where is inAppSessionAuth defined ??
|
||||
if (!isSSOWithRedirectURLAvailable || emmProvider.inAppSessionAuth === true) {
|
||||
if (!isSSOWithRedirectURLAvailable || managedConfig?.inAppSessionAuth === 'true') {
|
||||
//fixme: force it to get here
|
||||
return (
|
||||
<SSOWithWebView
|
||||
{...props}
|
||||
@@ -118,4 +119,4 @@ const SSO = ({config, serverUrl, ssoType, theme}: SSOProps) => {
|
||||
return <SSOWithRedirectURL {...props}/>;
|
||||
};
|
||||
|
||||
export default React.memo(SSO);
|
||||
export default SSO;
|
||||
|
||||
@@ -17,8 +17,7 @@ import urlParse from 'url-parse';
|
||||
|
||||
import {Client4} from '@client/rest';
|
||||
import Loading from '@components/loading';
|
||||
import StatusBar from '@components/status_bar';
|
||||
import ViewTypes from '@constants/view';
|
||||
import {Authentication} from '@constants';
|
||||
import {popTopScreen} from '@screens/navigation';
|
||||
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
|
||||
|
||||
@@ -69,15 +68,6 @@ interface SSOWithWebViewProps {
|
||||
theme: Partial<Theme>
|
||||
}
|
||||
|
||||
// type CookieResponseType = {
|
||||
// MMAUTHTOKEN: string | {
|
||||
// value: string
|
||||
// };
|
||||
// MMCSRF: string | {
|
||||
// value: string
|
||||
// };
|
||||
// }
|
||||
|
||||
function SSOWithWebView({completeUrlPath, loginError, loginUrl, onCSRFToken, onMMToken, serverUrl, ssoType, theme}: SSOWithWebViewProps) {
|
||||
const style = getStyleSheet(theme);
|
||||
const intl = useIntl();
|
||||
@@ -187,7 +177,7 @@ function SSOWithWebView({completeUrlPath, loginError, loginUrl, onCSRFToken, onM
|
||||
const parsed = urlParse(url);
|
||||
|
||||
let isLastRedirect = url.includes(completeUrlPath);
|
||||
if (ssoType === ViewTypes.SAML) {
|
||||
if (ssoType === Authentication.SAML) {
|
||||
isLastRedirect = isLastRedirect && !parsed.query;
|
||||
}
|
||||
|
||||
@@ -198,7 +188,7 @@ function SSOWithWebView({completeUrlPath, loginError, loginUrl, onCSRFToken, onM
|
||||
|
||||
const renderWebView = () => {
|
||||
if (shouldRenderWebView) {
|
||||
const userAgent = ssoType === ViewTypes.GOOGLE ? 'Mozilla/5.0 (Linux; Android 10; Android SDK built for x86 Build/LMY48X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.117 Mobile Safari/608.2.11' : undefined;
|
||||
const userAgent = ssoType === Authentication.GOOGLE ? 'Mozilla/5.0 (Linux; Android 10; Android SDK built for x86 Build/LMY48X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.117 Mobile Safari/608.2.11' : undefined;
|
||||
return (
|
||||
<WebView
|
||||
automaticallyAdjustContentInsets={false}
|
||||
@@ -225,7 +215,6 @@ function SSOWithWebView({completeUrlPath, loginError, loginUrl, onCSRFToken, onM
|
||||
style={style.container}
|
||||
testID='sso.webview'
|
||||
>
|
||||
<StatusBar/>
|
||||
{error || loginError ? (
|
||||
<View style={style.errorContainer}>
|
||||
<Text style={style.errorText}>{error || loginError}</Text>
|
||||
|
||||
Reference in New Issue
Block a user