refactor: Use generateAuthUrl method instead of createAuthData

This commit is contained in:
Faruk AYDIN
2022-11-10 18:50:36 +01:00
parent 10e2794ff9
commit 81c41ef5ee
21 changed files with 42 additions and 50 deletions

View File

@@ -0,0 +1,23 @@
import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url';
export default async function generateAuthUrl($: IGlobalVariable) {
const scopes = ['read:org', 'repo', 'user'];
const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl'
);
const redirectUri = oauthRedirectUrlField.value as string;
const searchParams = new URLSearchParams({
client_id: $.auth.data.consumerKey as string,
redirect_uri: redirectUri,
scope: scopes.join(','),
});
const url = `${
$.app.baseUrl
}/login/oauth/authorize?${searchParams.toString()}`;
await $.auth.set({
url,
});
}