@@ -45,6 +45,48 @@ export async function activate(context: vscode.ExtensionContext) {
45
45
46
46
context . subscriptions . push (
47
47
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
+ } ) ,
48
90
vscode . window . registerWebviewViewProvider ( 'ri-sidebar' , sidebarProvider ) ,
49
91
vscode . window . registerWebviewViewProvider ( 'ri-panel' , panelProvider , { webviewOptions : { retainContextWhenHidden : true } } ) ,
50
92
0 commit comments