Skip to content

Commit f51e2cc

Browse files
committed
#RIVS-297 - Investigate Cloud SSO
1 parent cd23d8d commit f51e2cc

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

package.json

+12
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@
8383
]
8484
},
8585
"commands": [
86+
{
87+
"command": "RedisForVSCode.signInWithGitHub",
88+
"title": "Sign in with Github",
89+
"category": "Redis for VS Code",
90+
"icon": "$(add)"
91+
},
92+
{
93+
"command": "RedisForVSCode.signInWithMicrosoft",
94+
"title": "Sign in with Microsoft",
95+
"category": "Redis for VS Code",
96+
"icon": "$(add)"
97+
},
8698
{
8799
"command": "RedisForVSCode.addCli",
88100
"title": "Add CLI",

src/extension.ts

+42
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,48 @@ export async function activate(context: vscode.ExtensionContext) {
4545

4646
context.subscriptions.push(
4747
myStatusBarItem,
48+
vscode.commands.registerCommand('RedisForVSCode.signInWithGitHub', async () => {
49+
try {
50+
const session = await vscode.authentication.getSession('github', ['user:email'], { forceNewSession: true })
51+
52+
if (session) {
53+
const response = await fetch('https://api.github.com/user', {
54+
headers: {
55+
Authorization: `token ${session.accessToken}`,
56+
'User-Agent': 'VSCode Extension',
57+
},
58+
})
59+
60+
if (!response.ok) {
61+
throw new Error(`Error: ${response.status} ${response.statusText}`)
62+
}
63+
64+
const userData = await response.json()
65+
66+
console.debug('github', { session, userData })
67+
68+
vscode.window.showInformationMessage(`Hello, ${userData.login}!`)
69+
} else {
70+
vscode.window.showErrorMessage('GitHub sign-in was not successful.')
71+
}
72+
} catch (error) {
73+
vscode.window.showErrorMessage(`Sign-in failed: ${error}`)
74+
}
75+
}),
76+
vscode.commands.registerCommand('RedisForVSCode.signInWithMicrosoft', async () => {
77+
try {
78+
const session = await vscode.authentication.getSession('microsoft', ['user.read'], { forceNewSession: true })
79+
80+
if (session) {
81+
console.debug('microsoft', { session })
82+
vscode.window.showInformationMessage(`Signed in as ${session.account.label}`)
83+
} else {
84+
vscode.window.showErrorMessage('Microsoft sign-in failed.')
85+
}
86+
} catch (error: any) {
87+
vscode.window.showErrorMessage(`Sign-in failed: ${error.message}`)
88+
}
89+
}),
4890
vscode.window.registerWebviewViewProvider('ri-sidebar', sidebarProvider),
4991
vscode.window.registerWebviewViewProvider('ri-panel', panelProvider, { webviewOptions: { retainContextWhenHidden: true } }),
5092

0 commit comments

Comments
 (0)