/// <summary> /// /// </summary> /// <param name="tokenScope"></param> /// <param name="personalAccessTokenStore"></param> public GithubAuthentication( GithubTokenScope tokenScope, ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationCodeDelegate acquireAuthenticationCodeCallback, AuthenticationResultDelegate authenticationResultCallback) { if (tokenScope == null) throw new ArgumentNullException("tokenScope", "The parameter `tokenScope` is null or invalid."); if (personalAccessTokenStore == null) throw new ArgumentNullException("personalAccessTokenStore", "The parameter `personalAccessTokenStore` is null or invalid."); if (acquireCredentialsCallback == null) throw new ArgumentNullException("acquireCredentialsCallback", "The parameter `acquireCredentialsCallback` is null or invalid."); if (acquireAuthenticationCodeCallback == null) throw new ArgumentNullException("acquireAuthenticationCodeCallback", "The parameter `acquireAuthenticationCodeCallback` is null or invalid."); TokenScope = tokenScope; PersonalAccessTokenStore = personalAccessTokenStore; GithubAuthority = new GithubAuthority(); AcquireCredentialsCallback = acquireCredentialsCallback; AcquireAuthenticationCodeCallback = acquireAuthenticationCodeCallback; AuthenticationResultCallback = authenticationResultCallback; }
/// <summary> /// Gets a configured authentication object for 'github.com'. /// </summary> /// <param name="targetUri"> /// The uniform resource indicator of the resource which requires authentication. /// </param> /// <param name="tokenScope">The desired scope of any personal access tokens acquired.</param> /// <param name="personalAccessTokenStore"> /// A secure secret store for any personal access tokens acquired. /// </param> /// <param name="authentication">(out) The authentication object if successful.</param> /// <returns>True if success; otherwise false.</returns> public static BaseAuthentication GetAuthentication( TargetUri targetUri, TokenScope tokenScope, ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationCodeDelegate acquireAuthenticationCodeCallback, AuthenticationResultDelegate authenticationResultCallback) { const string GitHubBaseUrlHost = "github.com"; BaseAuthentication authentication = null; BaseSecureStore.ValidateTargetUri(targetUri); if (personalAccessTokenStore == null) { throw new ArgumentNullException("personalAccessTokenStore", "The `personalAccessTokenStore` is null or invalid."); } if (targetUri.DnsSafeHost.EndsWith(GitHubBaseUrlHost, StringComparison.OrdinalIgnoreCase)) { authentication = new Authentication(targetUri, tokenScope, personalAccessTokenStore, acquireCredentialsCallback, acquireAuthenticationCodeCallback, authenticationResultCallback); Git.Trace.WriteLine($"created GitHub authentication for '{targetUri}'."); } else { authentication = null; Git.Trace.WriteLine($"not github.com, authentication creation aborted."); } return(authentication); }
/// <summary> /// Creates a new authentication /// </summary> /// <param name="targetUri"> /// The uniform resource indicator of the resource which requires authentication. /// </param> /// <param name="tokenScope">The desired scope of any personal access tokens acquired.</param> /// <param name="personalAccessTokenStore"> /// A secure secret store for any personal access tokens acquired. /// </param> public Authentication( TargetUri targetUri, TokenScope tokenScope, ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationCodeDelegate acquireAuthenticationCodeCallback, AuthenticationResultDelegate authenticationResultCallback) { if (tokenScope == null) { throw new ArgumentNullException("tokenScope", "The parameter `tokenScope` is null or invalid."); } if (personalAccessTokenStore == null) { throw new ArgumentNullException("personalAccessTokenStore", "The parameter `personalAccessTokenStore` is null or invalid."); } if (acquireCredentialsCallback == null) { throw new ArgumentNullException("acquireCredentialsCallback", "The parameter `acquireCredentialsCallback` is null or invalid."); } if (acquireAuthenticationCodeCallback == null) { throw new ArgumentNullException("acquireAuthenticationCodeCallback", "The parameter `acquireAuthenticationCodeCallback` is null or invalid."); } TokenScope = tokenScope; PersonalAccessTokenStore = personalAccessTokenStore; Authority = new Authority(targetUri); AcquireCredentialsCallback = acquireCredentialsCallback; AcquireAuthenticationCodeCallback = acquireAuthenticationCodeCallback; AuthenticationResultCallback = authenticationResultCallback; }
/// <summary> /// Creates a new authentication /// </summary> /// <param name="targetUri"> /// The uniform resource indicator of the resource which requires authentication. /// </param> /// <param name="tokenScope">The desired scope of any personal access tokens acquired.</param> /// <param name="personalAccessTokenStore"> /// A secure secret store for any personal access tokens acquired. /// </param> public Authentication( RuntimeContext context, TargetUri targetUri, TokenScope tokenScope, ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationCodeDelegate acquireAuthenticationCodeCallback, AuthenticationResultDelegate authenticationResultCallback) : base(context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } TokenScope = tokenScope ?? throw new ArgumentNullException(nameof(tokenScope)); PersonalAccessTokenStore = personalAccessTokenStore ?? throw new ArgumentNullException(nameof(personalAccessTokenStore)); AcquireCredentialsCallback = acquireCredentialsCallback ?? throw new ArgumentNullException(nameof(acquireCredentialsCallback)); AcquireAuthenticationCodeCallback = acquireAuthenticationCodeCallback ?? throw new ArgumentNullException(nameof(acquireAuthenticationCodeCallback)); Authority = new Authority(context, NormalizeUri(targetUri)); AuthenticationResultCallback = authenticationResultCallback; }
/// <summary> /// Gets a configured authentication object for 'github.com'. /// <para/> /// Returns a `<see cref="Authentication"/>` if successful; otherwise `<see langword="null"/>`. /// </summary> /// <param name="targetUri">The uniform resource indicator of the resource which requires authentication.</param> /// <param name="tokenScope">The desired scope of any personal access tokens acquired.</param> /// <param name="personalAccessTokenStore">A secure secret store for any personal access tokens acquired.</param> /// <param name="authentication">(out) The authentication object if successful.</param> public static BaseAuthentication GetAuthentication( RuntimeContext context, TargetUri targetUri, TokenScope tokenScope, ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationCodeDelegate acquireAuthenticationCodeCallback, AuthenticationResultDelegate authenticationResultCallback) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (targetUri is null) { throw new ArgumentNullException(nameof(targetUri)); } if (personalAccessTokenStore is null) { throw new ArgumentNullException(nameof(personalAccessTokenStore)); } BaseAuthentication authentication = null; if (targetUri.DnsSafeHost.EndsWith(GitHubBaseUrlHost, StringComparison.OrdinalIgnoreCase)) { var normalizedTargetUri = NormalizeUri(targetUri); authentication = new Authentication(context, normalizedTargetUri, tokenScope, personalAccessTokenStore, acquireCredentialsCallback, acquireAuthenticationCodeCallback, authenticationResultCallback); context.Trace.WriteLine($"created GitHub authentication for '{normalizedTargetUri}'."); } else { authentication = null; } return(authentication); }
/// <summary> /// Creates a new authentication /// </summary> /// <param name="targetUri"> /// The uniform resource indicator of the resource which requires authentication. /// </param> /// <param name="tokenScope">The desired scope of any personal access tokens acquired.</param> /// <param name="personalAccessTokenStore"> /// A secure secret store for any personal access tokens acquired. /// </param> public Authentication( RuntimeContext context, TargetUri targetUri, TokenScope tokenScope, ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationCodeDelegate acquireAuthenticationCodeCallback, AuthenticationResultDelegate authenticationResultCallback) : base(context) { TokenScope = tokenScope ?? throw new ArgumentNullException("tokenScope", "The parameter `tokenScope` is null or invalid."); PersonalAccessTokenStore = personalAccessTokenStore ?? throw new ArgumentNullException("personalAccessTokenStore", "The parameter `personalAccessTokenStore` is null or invalid."); AcquireCredentialsCallback = acquireCredentialsCallback ?? throw new ArgumentNullException("acquireCredentialsCallback", "The parameter `acquireCredentialsCallback` is null or invalid."); AcquireAuthenticationCodeCallback = acquireAuthenticationCodeCallback ?? throw new ArgumentNullException("acquireAuthenticationCodeCallback", "The parameter `acquireAuthenticationCodeCallback` is null or invalid."); Authority = new Authority(context, NormalizeUri(targetUri)); AuthenticationResultCallback = authenticationResultCallback; }
/// <summary> /// Gets a configured authentication object for 'github.com'. /// </summary> /// <param name="targetUri">The uniform resource indicator of the resource which requires /// authentication.</param> /// <param name="tokenScope">The desired scope of any personal access tokens aqcuired.</param> /// <param name="personalAccessTokenStore">A secure secret store for any personal access /// tokens acquired.</param> /// <param name="authentication">(out) The authenitcation object if successful.</param> /// <returns>True if success; otherwise false.</returns> public static bool GetAuthentication( Uri targetUri, GithubTokenScope tokenScope, ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationCodeDelegate acquireAuthenticationCodeCallback, AuthenticationResultDelegate authenticationResultCallback, out BaseAuthentication authentication) { const string GitHubBaseUrlHost = "github.com"; BaseSecureStore.ValidateTargetUri(targetUri); if (personalAccessTokenStore == null) throw new ArgumentNullException("personalAccessTokenStore", "The `personalAccessTokenStore` is null or invalid."); Trace.WriteLine("GithubAuthentication::GetAuthentication"); if (targetUri.DnsSafeHost.EndsWith(GitHubBaseUrlHost, StringComparison.OrdinalIgnoreCase)) { authentication = new GithubAuthentication(tokenScope, personalAccessTokenStore, acquireCredentialsCallback, acquireAuthenticationCodeCallback, authenticationResultCallback); Trace.WriteLine(" authentication for GitHub created"); } else { authentication = null; Trace.WriteLine(" not github.com, authentication creation aborted"); } return authentication != null; }