Skip to content

Commit

Permalink
Adds more validations
Browse files Browse the repository at this point in the history
  • Loading branch information
pastuxso committed Oct 25, 2024
1 parent da11bcf commit 5494cbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ export class RunmeExtension {
const statefulAuthProvider = new StatefulAuthProvider(context, uriHandler)
context.subscriptions.push(statefulAuthProvider)

const secrestAuthed = statefulAuthProvider.loadFromSecrets()
const forceLogin = kernel.isFeatureOn(FeatureName.ForceLogin) || (await secrestAuthed)
const secrestAuthed = await statefulAuthProvider.loadFromSecrets()
const forceLogin = kernel.isFeatureOn(FeatureName.ForceLogin) || secrestAuthed
const silent = forceLogin ? undefined : true

getPlatformAuthSession(forceLogin, silent)
Expand Down
13 changes: 7 additions & 6 deletions src/extension/provider/statefulAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,14 @@ export class StatefulAuthProvider implements AuthenticationProvider, Disposable

public async loadFromSecrets() {
const secretsFile = '/etc/secrets/playground-dev'
if (!secretsFile) {
logger.info('Skip authentication from secrets file')
return
}

const secretsUri = Uri.parse(secretsFile)
const hasSecretsFile = await workspace.fs.stat(secretsUri).then(
() => true,
() => false,
)

if (!hasSecretsFile) {
logger.info('No secrets file found')
logger.info('No secrets file found, skipping load from secrets')
return
}

Expand All @@ -276,6 +271,12 @@ export class StatefulAuthProvider implements AuthenticationProvider, Disposable

try {
const { name, email } = await this.getUserInfo(token)

if (!name || !email) {
logger.error('Failed to get user info from JWT token')
return
}

const session: StatefulAuthSession = {
accessToken: token,
expiresIn: secsToUnixTime(exp),
Expand Down

0 comments on commit 5494cbb

Please sign in to comment.