/// <summary> /// Identify the Hosting service from the the targetUri. /// <para/> /// Returns a `<see cref="BaseAuthentication"/>` instance if the `<paramref name="targetUri"/>` represents Bitbucket; otherwise `<see langword=""="null"/>`. /// </summary> /// <param name="targetUri"></param> public static BaseAuthentication GetAuthentication( RuntimeContext context, TargetUri targetUri, ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationOAuthDelegate acquireAuthenticationOAuthCallback) { BaseAuthentication authentication = null; BaseSecureStore.ValidateTargetUri(targetUri); if (personalAccessTokenStore == null) { throw new ArgumentNullException(nameof(personalAccessTokenStore), $"The `{nameof(personalAccessTokenStore)}` is null or invalid."); } if (targetUri.QueryUri.DnsSafeHost.EndsWith(BitbucketBaseUrlHost, StringComparison.OrdinalIgnoreCase)) { authentication = new Authentication(context, personalAccessTokenStore, acquireCredentialsCallback, acquireAuthenticationOAuthCallback); context.Trace.WriteLine("authentication for Bitbucket created"); } else { authentication = null; } return(authentication); }
/// <summary> /// Default constructor /// </summary> /// <param name="personalAccessTokenStore">where to store validated credentials</param> /// <param name="acquireCredentialsCallback"> /// what to call to promot the user for Basic Auth credentials /// </param> /// <param name="acquireAuthenticationOAuthCallback"> /// what to call to prompt the user to run the OAuth process /// </param> public Authentication(ICredentialStore personalAccessTokenStore, AcquireCredentialsDelegate acquireCredentialsCallback, AcquireAuthenticationOAuthDelegate acquireAuthenticationOAuthCallback) { if (personalAccessTokenStore == null) { throw new ArgumentNullException(nameof(personalAccessTokenStore), $"The parameter `{nameof(personalAccessTokenStore)}` is null or invalid."); } PersonalAccessTokenStore = personalAccessTokenStore; BitbucketAuthority = new Authority(); TokenScope = TokenScope.SnippetWrite | TokenScope.RepositoryWrite; AcquireCredentialsCallback = acquireCredentialsCallback; AcquireAuthenticationOAuthCallback = acquireAuthenticationOAuthCallback; }