Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Credentials.cs « LibGit2Sharp - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: adf9582fe42006a174e9c90000f18c15adeda5c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using LibGit2Sharp.Core;
using LibGit2Sharp.Handlers;

namespace LibGit2Sharp
{
    /// <summary>
    /// Class that holds credentials for remote repository access.
    /// </summary>
    public abstract class Credentials
    {
        /// <summary>
        /// Callback to acquire a credential object.
        /// </summary>
        /// <param name="cred">The newly created credential object.</param>
        /// <param name="url">The resource for which we are demanding a credential.</param>
        /// <param name="usernameFromUrl">The username that was embedded in a "user@host"</param>
        /// <param name="types">A bitmask stating which cred types are OK to return.</param>
        /// <param name="payload">The payload provided when specifying this callback.</param>
        /// <returns>0 for success, &lt; 0 to indicate an error, &gt; 0 to indicate no credential was acquired.</returns>
        protected internal abstract int GitCredentialHandler(out IntPtr cred, IntPtr url, IntPtr usernameFromUrl, GitCredentialType types, IntPtr payload);
    }

    internal interface ICredentialsProvider
    {
        /// <summary>
        /// The <see cref="Credentials"/> to authenticate with during the push.
        /// </summary>
        [Obsolete("This will be removed in future release. Use CredentialsProvider.")]
        Credentials Credentials { get; }

        /// <summary>
        /// Handler to generate <see cref="LibGit2Sharp.Credentials"/> for authentication.
        /// </summary>
        CredentialsHandler CredentialsProvider { get; }
    }

    internal static class CredentialsProviderExtensions
    {
        public static CredentialsHandler GetCredentialsHandler(this ICredentialsProvider provider)
        {
            if (provider == null)
            {
                return null;
            }

            if (provider.CredentialsProvider != null)
            {
                return provider.CredentialsProvider;
            }

            if (provider.Credentials == null)
            {
                return null;
            }

            return (url, user, type) => provider.Credentials;
        }
    }
}