-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement authentication and secret storage capability (#84)
CLOSE #72 https://linear.app/sourcegraph/issue/CODY-3619/implement-ivscredentialstorageservice-interface-for-storing-secrets https://linear.app/sourcegraph/issue/CODY-3618/agent-api-for-secret-storage-capability https://linear.app/sourcegraph/issue/CODY-3617/implement-agent-requests-for-secret-storage-capability Try logout and then log back into Cody to confirm you can now use token redirect and secret storage via Agent: ![image](https://github.com/user-attachments/assets/cf7c1838-11a5-44d0-b655-eeb639259abe) This PR enables client capability for authentication (added in sourcegraph/cody#5325) and secrets (added in sourcegraph/cody#5348) that allows users to use the native webview for authentication in Cody for Visual Studio. The protocols for secret storage operations have also been implemented and the secrets will be stored in [IVsCredentialStorageService](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.connected.credentialstorage?view=visualstudiosdk-2017). Demo: https://github.com/user-attachments/assets/d21c8c2f-2667-426a-9c4d-991b7645d2e5 --------- Co-authored-by: Piotr Karczmarz <piotr@karczmarz.com>
- Loading branch information
1 parent
8c274b0
commit 32e933b
Showing
22 changed files
with
247 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Microsoft.VisualStudio.Shell.Connected.CredentialStorage; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Cody.AgentTester | ||
{ | ||
public class FakeSecretStorageProvider : IVsCredentialStorageService | ||
{ | ||
private Dictionary<IVsCredentialKey, IVsCredential> _credentials = new Dictionary<IVsCredentialKey, IVsCredential>(); | ||
|
||
public IVsCredential Add(IVsCredentialKey key, string value) | ||
{ | ||
var credential = new FakeCredential(value); | ||
_credentials[key] = credential; | ||
return credential; | ||
} | ||
public IVsCredential Retrieve(IVsCredentialKey key) | ||
{ | ||
return _credentials[key]; | ||
} | ||
public IEnumerable<IVsCredential> RetrieveAll(string key) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
public bool Remove(IVsCredentialKey key) | ||
{ | ||
return _credentials.Remove(key); | ||
} | ||
public IVsCredentialKey CreateCredentialKey(string featureName, string resource, string userName, string type) | ||
{ | ||
return new FakeCredentialKey(featureName, resource, userName, type); | ||
} | ||
|
||
private class FakeCredentialKey : IVsCredentialKey | ||
{ | ||
public string FeatureName { get; set; } | ||
public string UserName { get; set; } | ||
public string Type { get; set; } | ||
public string Resource { get; set; } | ||
|
||
public FakeCredentialKey(string featureName, string resource, string userName, string type) | ||
{ | ||
FeatureName = featureName; | ||
UserName = userName; | ||
Type = type; | ||
Resource = resource; | ||
} | ||
} | ||
|
||
private class FakeCredential : IVsCredential | ||
{ | ||
public string FeatureName { get; set; } | ||
public string UserName { get; set; } | ||
public string Type { get; set; } | ||
public string Resource { get; set; } | ||
|
||
public string TokenValue { get; set; } | ||
|
||
public bool RefreshTokenValue() | ||
{ | ||
return true; | ||
} | ||
public void SetTokenValue(string tokenValue) | ||
{ | ||
TokenValue = tokenValue; | ||
} | ||
public string GetProperty(string name) | ||
{ | ||
return name; | ||
} | ||
public bool SetProperty(string name, string value) | ||
{ | ||
return true; | ||
} | ||
public FakeCredential(string tokenValue) | ||
{ | ||
TokenValue = tokenValue; | ||
} | ||
} | ||
} | ||
} |
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
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,10 @@ | ||
namespace Cody.Core.Infrastructure | ||
{ | ||
public interface ISecretStorageService | ||
{ | ||
void Set(string key, string value); | ||
string Get(string key); | ||
void Delete(string key); | ||
string AccessToken { get; set; } | ||
} | ||
} |
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
Oops, something went wrong.