Get OAuth-Callback URLs from backend

This commit is contained in:
Jan Oberhauser 2020-09-30 15:50:43 +02:00
parent 6f576b3da9
commit f1680386ca
6 changed files with 26 additions and 3 deletions

View file

@ -288,6 +288,10 @@ export interface IN8nUISettings {
saveManualExecutions: boolean;
executionTimeout: number;
maxExecutionTimeout: number;
oauthCallbackUrls: {
oauth1: string;
oauth2: string;
};
timezone: string;
urlBaseWebhook: string;
versionCli: string;

View file

@ -1617,7 +1617,9 @@ class App {
// Returns the settings which are needed in the UI
this.app.get(`/${this.restEndpoint}/settings`, ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<IN8nUISettings> => {
return {
const urlBaseWebhook = WebhookHelpers.getWebhookBaseUrl();
const settings: IN8nUISettings = {
endpointWebhook: this.endpointWebhook,
endpointWebhookTest: this.endpointWebhookTest,
saveDataErrorExecution: this.saveDataErrorExecution,
@ -1626,8 +1628,12 @@ class App {
executionTimeout: this.executionTimeout,
maxExecutionTimeout: this.maxExecutionTimeout,
timezone: this.timezone,
urlBaseWebhook: WebhookHelpers.getWebhookBaseUrl(),
urlBaseWebhook,
versionCli: this.versions!.cli,
oauthCallbackUrls: {
'oauth1': urlBaseWebhook + `${this.restEndpoint}/oauth1-credential/callback`,
'oauth2': urlBaseWebhook + `${this.restEndpoint}/oauth2-credential/callback`,
}
};
}));

View file

@ -399,6 +399,10 @@ export interface IN8nUISettings {
timezone: string;
executionTimeout: number;
maxExecutionTimeout: number;
oauthCallbackUrls: {
oauth1: string;
oauth2: string;
};
urlBaseWebhook: string;
versionCli: string;
}

View file

@ -235,7 +235,7 @@ export default mixins(
oAuthCallbackUrl (): string {
const types = this.parentTypes(this.credentialTypeData.name);
const oauthType = (this.credentialTypeData.name === 'oAuth2Api' || types.includes('oAuth2Api')) ? 'oauth2' : 'oauth1';
return this.$store.getters.getWebhookBaseUrl + `rest/${oauthType}-credential/callback`;
return this.$store.getters.oauthCallbackUrls[oauthType];
},
requiredPropertiesFilled (): boolean {
for (const property of this.credentialProperties) {

View file

@ -8,6 +8,7 @@ import {
IConnection,
IConnections,
ICredentialType,
IDataObject,
INodeConnections,
INodeIssueData,
INodeTypeDescription,
@ -55,6 +56,7 @@ export const store = new Vuex.Store({
executionTimeout: -1,
maxExecutionTimeout: Number.MAX_SAFE_INTEGER,
versionCli: '0.0.0',
oauthCallbackUrls: {},
workflowExecutionData: null as IExecutionResponse | null,
lastSelectedNode: null as string | null,
lastSelectedNodeOutputIndex: null as number | null,
@ -490,6 +492,9 @@ export const store = new Vuex.Store({
setVersionCli (state, version: string) {
Vue.set(state, 'versionCli', version);
},
setOauthCallbackUrls(state, urls: IDataObject) {
Vue.set(state, 'oauthCallbackUrls', urls);
},
addNodeType (state, typeData: INodeTypeDescription) {
if (!typeData.hasOwnProperty('name')) {
@ -609,6 +614,9 @@ export const store = new Vuex.Store({
versionCli: (state): string => {
return state.versionCli;
},
oauthCallbackUrls: (state): object => {
return state.oauthCallbackUrls;
},
// Push Connection
pushConnectionActive: (state): boolean => {

View file

@ -1873,6 +1873,7 @@ export default mixins(
this.$store.commit('setExecutionTimeout', settings.executionTimeout);
this.$store.commit('setMaxExecutionTimeout', settings.maxExecutionTimeout);
this.$store.commit('setVersionCli', settings.versionCli);
this.$store.commit('setOauthCallbackUrls', settings.oauthCallbackUrls);
},
async loadNodeTypes (): Promise<void> {
const nodeTypes = await this.restApi().getNodeTypes();