diff --git a/services/github/pod-github/src/platform.ts b/services/github/pod-github/src/platform.ts index edf1929209..97455c5eb0 100644 --- a/services/github/pod-github/src/platform.ts +++ b/services/github/pod-github/src/platform.ts @@ -738,7 +738,8 @@ export class PlatformWorker { } async checkRefreshToken (ctx: MeasureContext, auth: GithubUserRecord, force: boolean = false): Promise { - if (auth.refreshToken != null && auth.expiresIn != null && auth.expiresIn < Date.now() / 1000) { + const expired = auth.expiresIn != null && auth.expiresIn < Date.now() / 1000 + if (auth.refreshToken != null && (force || expired)) { const uri = 'https://github.com/login/oauth/access_token?' + makeQuery({ diff --git a/services/github/pod-github/src/users.ts b/services/github/pod-github/src/users.ts index 3771cd52be..ccb12372cd 100644 --- a/services/github/pod-github/src/users.ts +++ b/services/github/pod-github/src/users.ts @@ -36,11 +36,12 @@ export class UserManager { } private secretToUserRecord (secret: IntegrationSecret, login: string): GithubUserRecord | undefined { + const parsed = JSON.parse(secret.secret) ?? {} // TODO: Add security return { - ...(JSON.parse(secret.secret) ?? {}), // TODO: Add security + ...parsed, account: secret.socialId, _id: login, - accounts: {} + accounts: parsed.accounts ?? {} } } diff --git a/services/github/pod-github/src/worker.ts b/services/github/pod-github/src/worker.ts index 244de40828..530f0d35b0 100644 --- a/services/github/pod-github/src/worker.ts +++ b/services/github/pod-github/src/worker.ts @@ -643,6 +643,7 @@ export class GithubWorker implements IntegrationManager { ctx.info('get octokit', { account, recordId: record._id, workspace: this.workspace.uuid }) if (!(await this.platform.checkRefreshToken(ctx, record))) { record.octokit = undefined + return undefined } if (record.octokit !== undefined) { return record.octokit