-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from arkahna/FB-73-ability-to-auth-as-a-user-f…
…rom-the-command-line-2 Fb 73 ability to auth as a user from the command line 2
- Loading branch information
Showing
54 changed files
with
1,320 additions
and
1,057 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Command } from '@commander-js/extra-typings' | ||
import prompts from 'prompts' | ||
import { actionRunner } from '../lib/action-runner' | ||
import { readCurrentOrganization } from '../lib/current-organization' | ||
import { getValidToken } from '../lib/get-valid-token' | ||
|
||
export function accountCommand() { | ||
return new Command('account') | ||
.description( | ||
`Shows the account information of the currently logged in user`, | ||
) | ||
.option( | ||
'-v, --verbose', | ||
'Verbose output, show additional logging and tracing', | ||
false, | ||
) | ||
.option( | ||
'-n, --nonInteractive', | ||
"Don't prompt for missing options", | ||
!!process.env['CI'], | ||
) | ||
.action( | ||
actionRunner(async function codeGen(options) { | ||
prompts.override(options) | ||
|
||
let bearerToken: string | undefined | ||
if (!options.nonInteractive) { | ||
const token = await getValidToken() | ||
if (!token) { | ||
return | ||
} | ||
bearerToken = token | ||
} | ||
|
||
if (!bearerToken) { | ||
console.log('Not logged in') | ||
return | ||
} | ||
|
||
const decodedToken = parseJwt(bearerToken) | ||
|
||
console.log( | ||
JSON.stringify( | ||
{ | ||
id: decodedToken.oid, | ||
name: decodedToken.name, | ||
upn: decodedToken.upn, | ||
tenantId: decodedToken.tid, | ||
unique_name: decodedToken.unique_name, | ||
currentOrganization: await readCurrentOrganization( | ||
options.verbose, | ||
), | ||
}, | ||
null, | ||
2, | ||
), | ||
) | ||
}), | ||
) | ||
} | ||
|
||
function parseJwt(token: string) { | ||
return JSON.parse( | ||
Buffer.from(token.split('.')[1], 'base64').toString(), | ||
) as Record<string, string> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.