-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sign in feature with file addition to context (#61)
* Add sign in feature with file addition to context * Put yaml back. Bump changelog Signed-off-by: Aidan Jensen <[email protected]> * forgot json in the python-common version Signed-off-by: Aidan Jensen <[email protected]> * Bump version Signed-off-by: Aidan Jensen <[email protected]> * Update src/auth/auth.ts Co-authored-by: Paul Mandel <[email protected]> * Listen for create and delete file events for config --------- Signed-off-by: Aidan Jensen <[email protected]> Co-authored-by: artificial-smahon <[email protected]> Co-authored-by: Paul Mandel <[email protected]> Co-authored-by: Shawn Mahon <[email protected]>
- Loading branch information
1 parent
40b652e
commit dd68c12
Showing
6 changed files
with
131 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Change Log | ||
|
||
## [3.2.0] | ||
|
||
- Add Sign-In feature | ||
|
||
## [3.1.8] | ||
|
||
- Loading Config View | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,85 @@ | ||
/* | ||
Copyright 2022 Artificial, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { addFileToContext } from '../utils'; | ||
import { OutputLog } from '../providers/outputLogProvider'; | ||
|
||
export async function authExternalUriRegistration(context: vscode.ExtensionContext) { | ||
// Register a URI handler for the authentication callback | ||
vscode.window.registerUriHandler({ | ||
handleUri(uri: vscode.Uri): vscode.ProviderResult<void> { | ||
if (uri.path === '/auth-complete') { | ||
// Parse query parameters | ||
const query = new URLSearchParams(uri.query); | ||
const instanceURL = query.get('instanceURL'); | ||
const token = query.get('token'); | ||
|
||
if (instanceURL === null || token === null) { | ||
vscode.window.showErrorMessage('Sign in failed: missing instanceURL or token'); | ||
return; | ||
} | ||
// Convert instanceURL into a valid host for AC | ||
const u = new URL(instanceURL); | ||
|
||
const generatedObj = { | ||
artificial: { | ||
host: u.host, | ||
token: token, | ||
}, | ||
}; | ||
|
||
addFileToContext(JSON.stringify(generatedObj), 'generated.yaml'); | ||
|
||
vscode.window.showInformationMessage(`Sign in successful!. Please make sure generated.yaml is added to your .gitignore file`); | ||
} else { | ||
vscode.window.showErrorMessage(`Sign in failed: invalid URI path ${uri.path}`); | ||
} | ||
} | ||
}); | ||
|
||
// Register a sign in command | ||
context.subscriptions.push( | ||
vscode.commands.registerCommand(`adapterActions.signin`, async () => { | ||
// Ask for instance url | ||
const instanceUrl = await vscode.window.showInputBox({ | ||
prompt: 'Enter the URL of your instance', | ||
placeHolder: 'https://example.artificial.com', | ||
}); | ||
|
||
if (instanceUrl === undefined) { | ||
vscode.window.showErrorMessage('Sign in failed: missing instance URL'); | ||
return; | ||
} | ||
try { | ||
new URL(instanceUrl); | ||
} catch (e) { | ||
const log = OutputLog.getInstance(); | ||
log.log(`Error getting instance url during signin: ${e}`); | ||
vscode.window.showErrorMessage(`Sign in failed: invalid instance URL`); | ||
return; | ||
} | ||
|
||
// Get an externally addressable callback URI for the handler that the authentication provider can use | ||
const extensionId = 'artificial.artificial-workflow-extension'; | ||
const callbackUri = await vscode.env.asExternalUri( | ||
vscode.Uri.parse(`${instanceUrl}/app/#/vscode-login?instanceURL=${instanceUrl}&redirect=${vscode.env.uriScheme}://${extensionId}/auth-complete`) | ||
); | ||
vscode.env.openExternal(callbackUri); | ||
}) | ||
); | ||
|
||
} |
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