Fixes: Connecting slack commands from subdomain
This commit is contained in:
@@ -11,12 +11,14 @@ import HelpText from 'components/HelpText';
|
||||
import SlackButton from './components/SlackButton';
|
||||
import CollectionsStore from 'stores/CollectionsStore';
|
||||
import IntegrationsStore from 'stores/IntegrationsStore';
|
||||
import AuthStore from 'stores/AuthStore';
|
||||
import Notice from 'shared/components/Notice';
|
||||
import getQueryVariable from 'shared/utils/getQueryVariable';
|
||||
|
||||
type Props = {
|
||||
collections: CollectionsStore,
|
||||
integrations: IntegrationsStore,
|
||||
auth: AuthStore,
|
||||
};
|
||||
|
||||
@observer
|
||||
@@ -36,7 +38,8 @@ class Slack extends React.Component<Props> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { collections, integrations } = this.props;
|
||||
const { collections, integrations, auth } = this.props;
|
||||
const teamId = auth.team ? auth.team.id : '';
|
||||
|
||||
return (
|
||||
<CenteredContent>
|
||||
@@ -48,6 +51,12 @@ class Slack extends React.Component<Props> {
|
||||
Outline to your team. Try again?
|
||||
</Notice>
|
||||
)}
|
||||
{this.error === 'unauthenticated' && (
|
||||
<Notice>
|
||||
Something went wrong while authenticating your request. Please try
|
||||
logging in again?
|
||||
</Notice>
|
||||
)}
|
||||
<HelpText>
|
||||
Preview Outline links your team mates share and use the{' '}
|
||||
<Code>/outline</Code> slash command in Slack to search for documents
|
||||
@@ -60,7 +69,7 @@ class Slack extends React.Component<Props> {
|
||||
<SlackButton
|
||||
scopes={['commands', 'links:read', 'links:write']}
|
||||
redirectUri={`${BASE_URL}/auth/slack.commands`}
|
||||
state=""
|
||||
state={teamId}
|
||||
/>
|
||||
)}
|
||||
</p>
|
||||
@@ -130,4 +139,4 @@ const Code = styled.code`
|
||||
border-radius: 4px;
|
||||
`;
|
||||
|
||||
export default inject('collections', 'integrations')(Slack);
|
||||
export default inject('collections', 'integrations', 'auth')(Slack);
|
||||
|
||||
@@ -69,8 +69,9 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
|
||||
ctx.signIn(user, team, 'slack', isFirstSignin);
|
||||
});
|
||||
|
||||
router.get('slack.commands', auth(), async ctx => {
|
||||
const { code, error } = ctx.request.query;
|
||||
router.get('slack.commands', auth({ required: false }), async ctx => {
|
||||
const { code, state, error } = ctx.request.query;
|
||||
const user = ctx.state.user;
|
||||
ctx.assertPresent(code || error, 'code is required');
|
||||
|
||||
if (error) {
|
||||
@@ -78,9 +79,28 @@ router.get('slack.commands', auth(), async ctx => {
|
||||
return;
|
||||
}
|
||||
|
||||
// this code block accounts for the root domain being unable to
|
||||
// access authentcation for subdomains. We must forward to the appropriate
|
||||
// subdomain to complete the oauth flow
|
||||
if (!user) {
|
||||
if (state) {
|
||||
try {
|
||||
const team = await Team.findById(state);
|
||||
return ctx.redirect(
|
||||
`${team.url}/auth${ctx.request.path}?${ctx.request.querystring}`
|
||||
);
|
||||
} catch (err) {
|
||||
return ctx.redirect(
|
||||
`/settings/integrations/slack?error=unauthenticated`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return ctx.redirect(`/settings/integrations/slack?error=unauthenticated`);
|
||||
}
|
||||
}
|
||||
|
||||
const endpoint = `${process.env.URL || ''}/auth/slack.commands`;
|
||||
const data = await Slack.oauthAccess(code, endpoint);
|
||||
const user = ctx.state.user;
|
||||
|
||||
const authentication = await Authentication.create({
|
||||
service: 'slack',
|
||||
|
||||
Reference in New Issue
Block a user