Skip to content

Commit

Permalink
Attempt at Gitea support
Browse files Browse the repository at this point in the history
  • Loading branch information
hickford committed Oct 7, 2022
1 parent 9b3bf45 commit 670e856
Show file tree
Hide file tree
Showing 13 changed files with 672 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Git-Credential-Manager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Git-Credential-Manager.UI.Avalonia", "src\shared\Git-Credential-Manager.UI.Avalonia\Git-Credential-Manager.UI.Avalonia.csproj", "{35659127-8859-4DB9-8DD6-A08C1952632E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Git-Credential-Manager.UI.Windows", "src\windows\Git-Credential-Manager.UI.Windows\Git-Credential-Manager.UI.Windows.csproj", "{01BF56EC-AAC1-4BCA-8204-EE51D968DF5C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gitea", "src\shared\Gitea\Gitea.csproj", "{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -415,6 +416,23 @@ Global
{570897DC-A85C-4598-B793-9A00CF710119}.MacRelease|Any CPU.Build.0 = Release|Any CPU
{570897DC-A85C-4598-B793-9A00CF710119}.WindowsRelease|Any CPU.ActiveCfg = Release|Any CPU
{570897DC-A85C-4598-B793-9A00CF710119}.WindowsRelease|Any CPU.Build.0 = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.MacDebug|Any CPU.ActiveCfg = Debug|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.MacDebug|Any CPU.Build.0 = Debug|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.Release|Any CPU.Build.0 = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.WindowsDebug|Any CPU.ActiveCfg = Debug|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.WindowsDebug|Any CPU.Build.0 = Debug|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.LinuxDebug|Any CPU.ActiveCfg = Debug|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.LinuxDebug|Any CPU.Build.0 = Debug|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.LinuxRelease|Any CPU.ActiveCfg = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.LinuxRelease|Any CPU.Build.0 = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.MacRelease|Any CPU.ActiveCfg = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.MacRelease|Any CPU.Build.0 = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.WindowsRelease|Any CPU.ActiveCfg = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7}.WindowsRelease|Any CPU.Build.0 = Release|Any CPU
{FEF135C0-F03B-4E19-8AD7-20DFC4DC76E7} = {D5277A0E-997E-453A-8CB9-4EFCC8B16A29}
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.MacDebug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Compared to Git's [built-in credential helpers][git-tools-credential-storage]
provides single-factor authentication support working on any HTTP-enabled Git
repository, GCM provides multi-factor authentication support for
[Azure DevOps][azure-devops], Azure DevOps Server (formerly Team Foundation
Server), GitHub, Bitbucket, and GitLab.
Server), GitHub, Bitbucket, GitLab and Gitea.

Git Credential Manager (GCM) replaces the .NET Framework-based
[Git Credential Manager for Windows][gcm-for-windows] (GCM), and the Java-based
Expand All @@ -36,6 +36,7 @@ Multi-factor authentication support for Azure DevOps|✓|✓|✓
Two-factor authentication support for GitHub|✓|✓|✓
Two-factor authentication support for Bitbucket|✓|✓|✓
Two-factor authentication support for GitLab|✓|✓|✓
Two-factor authentication support for Gitea|✓|✓|✓
Windows Integrated Authentication (NTLM/Kerberos) support|✓|_N/A_|_N/A_
Basic HTTP authentication support|✓|✓|✓
Proxy support|✓|✓|✓
Expand Down Expand Up @@ -283,6 +284,7 @@ See detailed information [here][gcm-http-proxy].
- [Host provider specification][gcm-host-provider]
- [Azure Repos OAuth tokens][gcm-azure-tokens]
- [GitLab support][gcm-gitlab]
- [Gitea support][gcm-gitea]

## Experimental Features

Expand Down Expand Up @@ -322,6 +324,7 @@ When using GitHub logos, please be sure to follow the
[gcm-for-mac-and-linux]: https://github.com/microsoft/Git-Credential-Manager-for-Mac-and-Linux
[gcm-for-windows]: https://github.com/microsoft/Git-Credential-Manager-for-Windows
[gcm-gitlab]: docs/gitlab.md
[gcm-gitea]: docs/gitea.md
[gcm-host-provider]: docs/hostprovider.md
[gcm-http-proxy]: docs/netconfig.md#http-proxy
[gcm-license]: LICENSE
Expand Down
27 changes: 27 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ ID|Provider
`github`|GitHub
`bitbucket`|Bitbucket
`gitlab`|GitLab _(supports OAuth in browser, personal access token and Basic Authentication)_
`gitea`|Gitea _(supports OAuth in browser, personal access token and Basic Authentication)_
`generic`|Generic (any other provider not listed above)

Automatic provider selection is based on the remote URL.
Expand Down Expand Up @@ -350,6 +351,31 @@ git config --global credential.namespace "my-namespace"

---

### credential.giteaAuthModes

Override the available authentication modes presented during Gitea
authentication. If this option is not set, then the available authentication
modes will be automatically detected.

**Note:** This setting supports multiple values separated by commas.

Value|Authentication Mode
-|-
_(unset)_|Automatically detect modes
`browser`|OAuth authentication via a web browser _(requires a GUI)_
`basic`|Basic authentication using username and password
`pat`|Personal Access Token (pat)-based authentication

#### Example

```shell
git config --global credential.giteaAuthModes "browser"
```

**Also see: [GCM_GITEA_AUTHMODES][gcm-gitea-authmodes]**

---

### credential.credentialStore

Select the type of credential store to use on supported platforms.
Expand Down Expand Up @@ -611,6 +637,7 @@ git config --global credential.azreposCredentialType oauth
[gcm-dpapi-store-path]: environment.md#GCM_DPAPI_STORE_PATH
[gcm-github-authmodes]: environment.md#GCM_GITHUB_AUTHMODES
[gcm-gitlab-authmodes]:environment.md#GCM_GITLAB_AUTHMODES
[gcm-gitea-authmodes]:environment.md#GCM_GITEA_AUTHMODES
[gcm-gui-prompt]: environment.md#GCM_GUI_PROMPT
[gcm-http-proxy]: environment.md#GCM_HTTP_PROXY-deprecated
[gcm-interactive]: environment.md#GCM_INTERACTIVE
Expand Down
33 changes: 33 additions & 0 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ ID|Provider
`azure-repos`|Azure Repos
`github`|GitHub
`gitlab`|GitLab _(supports OAuth in browser, personal access token and Basic Authentication)_
`gitea`|Gitea _(supports OAuth in browser, personal access token and Basic Authentication)_
`generic`|Generic (any other provider not listed above)

Automatic provider selection is based on the remote URL.
Expand Down Expand Up @@ -498,6 +499,37 @@ export GCM_GITLAB_AUTHMODES="browser"

---

### GCM_GITEA_AUTHMODES

Override the available authentication modes presented during Gitea
authentication. If this option is not set, then the available authentication
modes will be automatically detected.

**Note:** This setting supports multiple values separated by commas.

Value|Authentication Mode
-|-
_(unset)_|Automatically detect modes
`browser`|OAuth authentication via a web browser _(requires a GUI)_
`basic`|Basic authentication using username and password
`pat`|Personal Access Token (pat)-based authentication

#### Windows

```batch
SET GCM_GITEA_AUTHMODES="browser"
```

#### macOS/Linux

```bash
export GCM_GITEA_AUTHMODES="browser"
```

**Also see: [credential.giteaAuthModes][credential-giteaauthmodes]**

---

### GCM_NAMESPACE

Use a custom namespace prefix for credentials read and written in the OS
Expand Down Expand Up @@ -752,6 +784,7 @@ export GCM_AZREPOS_CREDENTIALTYPE="oauth"
[credential-dpapi-store-path]: configuration.md#credentialdpapistorepath
[credential-githubauthmodes]: configuration.md#credentialgitHubAuthModes
[credential-gitlabauthmodes]: configuration.md#credentialgitLabAuthModes
[credential-giteaauthmodes]: configuration.md#credentialgiteaAuthModes
[credential-guiprompt]: configuration.md#credentialguiprompt
[credential-httpproxy]: configuration.md#credentialhttpProxy-deprecated
[credential-interactive]: configuration.md#credentialinteractive
Expand Down
48 changes: 48 additions & 0 deletions docs/gitea.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Gitea support

GCM requires Gitea v1.18 or later.

## Config for a custom instance

1. In Settings / Applications, create an OAuth application, unchecking the
*Confidential* option (if this option is missing, the version of Gitea is too
old)
1. Copy the application ID and configure
`git config --global credential.https://gitea.example.com.GiteaDevClientId <APPLICATION_ID>`
1. Copy the application secret and configure
`git config --global credential.https://gitea.example.com.GiteaDevClientSecret
<APPLICATION_SECRET>`
1. Configure authentication modes to include 'browser'
`git config --global credential.https://gitea.example.com.GiteaAuthModes browser`
1. For good measure, configure
`git config --global credential.https://gitea.example.com.provider gitea`.
This may be necessary to recognise the domain as a Gitea instance.
1. Verify the config is as expected
`git config --global --get-urlmatch credential https://gitea.example.com`

## Clearing config

### Clearing config

```console
git config --global --unset-all credential.https://gitea.example.com.GiteaDevClientId
git config --global --unset-all credential.https://gitea.example.com.GiteaDevClientSecret
git config --global --unset-all credential.https://gitea.example.com.provider
```

## Preferences

```console
Select an authentication method for 'https://gitea.com/':
1. Web browser (default)
2. Personal access token
3. Username/password
option (enter for default):
```

If you have a preferred authentication mode, you can specify
[credential.giteaAuthModes][config-gitea-auth-modes]:

```console
git config --global credential.giteaauthmodes browser
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ProjectReference Include="..\Atlassian.Bitbucket\Atlassian.Bitbucket.csproj" />
<ProjectReference Include="..\GitHub\GitHub.csproj" />
<ProjectReference Include="..\GitLab\GitLab.csproj" />
<ProjectReference Include="..\Gitea\Gitea.csproj" />
<ProjectReference Include="..\Microsoft.AzureRepos\Microsoft.AzureRepos.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/shared/Git-Credential-Manager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Atlassian.Bitbucket;
using GitHub;
using GitLab;
using Gitea;
using Microsoft.AzureRepos;
using GitCredentialManager.Authentication;

Expand Down Expand Up @@ -37,6 +38,7 @@ public static void Main(string[] args)
app.RegisterProvider(new BitbucketHostProvider(context), HostProviderPriority.Normal);
app.RegisterProvider(new GitHubHostProvider(context), HostProviderPriority.Normal);
app.RegisterProvider(new GitLabHostProvider(context), HostProviderPriority.Normal);
app.RegisterProvider(new GiteaHostProvider(context), HostProviderPriority.Normal);
app.RegisterProvider(new GenericHostProvider(context), HostProviderPriority.Low);

int exitCode = app.RunAsync(args)
Expand Down
20 changes: 20 additions & 0 deletions src/shared/Gitea/Gitea.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OSPlatform)'=='windows'">netstandard2.0;net472</TargetFrameworks>
<AssemblyName>Gitea</AssemblyName>
<RootNamespace>Gitea</RootNamespace>
<IsTestProject>false</IsTestProject>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<Reference Include="System.Net.Http" />
</ItemGroup>

</Project>
Loading

0 comments on commit 670e856

Please sign in to comment.