Skip to content

Commit

Permalink
Add support for Auth Scheme customization (#8261)
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum authored Oct 23, 2024
1 parent 05f7875 commit 8c7c02d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
5 changes: 3 additions & 2 deletions app/constants/sso.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import LocalConfig from '@assets/config.json';
import keyMirror from '@utils/key_mirror';

export const REDIRECT_URL_SCHEME = 'mmauth://';
export const REDIRECT_URL_SCHEME_DEV = 'mmauthbeta://';
export const REDIRECT_URL_SCHEME = LocalConfig.AuthUrlScheme;
export const REDIRECT_URL_SCHEME_DEV = LocalConfig.AuthUrlSchemeDev;

const constants = keyMirror({
SAML: null,
Expand Down
3 changes: 2 additions & 1 deletion app/screens/sso/sso.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import React from 'react';

import LocalConfig from '@assets/config.json';
import Preferences from '@constants/preferences';
import {renderWithIntl} from '@test/intl-test-helper';

Expand All @@ -16,7 +17,7 @@ jest.mock('@utils/url', () => {

describe('SSO with redirect url', () => {
const baseProps = {
customUrlScheme: 'mmauthbeta://',
customUrlScheme: LocalConfig.AuthUrlSchemeDev,
doSSOLogin: jest.fn(),
intl: {},
loginError: '',
Expand Down
2 changes: 2 additions & 0 deletions assets/base/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"AuthUrlScheme": "mmauth://",
"AuthUrlSchemeDev": "mmauthbeta://",
"DefaultServerUrl": "",
"DefaultServerName": "",
"TestServerUrl": "http://localhost:8065",
Expand Down
32 changes: 24 additions & 8 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ lane :configure do
json['ShowOnboarding'] = true
end

# Configure the auth schemes
auth_scheme = ENV['APP_AUTH_SCHEME'].to_s.empty? ? 'mmauth' : ENV['APP_AUTH_SCHEME']
auth_scheme_dev = ENV['APP_AUTH_SCHEME_BETA'].to_s.empty? ? 'mmauthbeta' : ENV['APP_AUTH_SCHEME_BETA']
json["AuthUrlScheme"] = auth_scheme.end_with?('://') ? auth_scheme : "#{auth_scheme}://"
json["AuthUrlSchemeDev"] = auth_scheme_dev.end_with?('://') ? auth_scheme_dev : "#{auth_scheme_dev}://"

# Save the config.json file
save_json_as_file('../dist/assets/config.json', json)

Expand Down Expand Up @@ -473,7 +479,8 @@ platform :ios do

# Set the deep link prefix
app_scheme = ENV['APP_SCHEME'] || 'mattermost'
app_auth_scheme = ENV['BETA_BUILD'] == 'true' ? 'mmauthbeta' : 'mmauth'
app_auth_scheme = get_auth_scheme
UI.success "Update auth scheme to #{app_auth_scheme} #{ENV['BETA_BUILD']} authScheme #{ENV['APP_AUTH_SCHEME']} beta #{ENV['APP_AUTH_SCHEME_BETA']}"
update_info_plist(
xcodeproj: './ios/Mattermost.xcodeproj',
plist_path: 'Mattermost/Info.plist',
Expand Down Expand Up @@ -748,13 +755,14 @@ platform :android do
new_string: "scheme=\'#{app_scheme}\'"
)

if ENV['BETA_BUILD'] != 'true'
find_replace_string(
path_to_file: "./android/app/src/main/AndroidManifest.xml",
old_string: 'scheme="mmauthbeta"',
new_string: 'scheme="mmauth"',
)
end

app_auth_scheme = get_auth_scheme

find_replace_string(
path_to_file: "./android/app/src/main/AndroidManifest.xml",
old_string: 'scheme="mmauthbeta"',
new_string: "scheme=\"#{app_auth_scheme}\"",
)

helpers_dir = './android/app/src/main/java/com/mattermost/helpers/'
beta_dir = './android/app/src/main/java/com/mattermost/rnbeta/'
Expand Down Expand Up @@ -921,6 +929,14 @@ platform :android do
end
end

def get_auth_scheme
if ENV['BETA_BUILD'] == 'true'
ENV['APP_AUTH_SCHEME_BETA'].to_s.empty? ? 'mmauthbeta' : ENV['APP_AUTH_SCHEME_BETA']
else
ENV['APP_AUTH_SCHEME'].to_s.empty? ? 'mmauth' : ENV['APP_AUTH_SCHEME']
end
end

def load_config_json(json_path)
config_file = File.read(json_path)
JSON.parse(config_file)
Expand Down

0 comments on commit 8c7c02d

Please sign in to comment.