/// <summary>
 /// Construct a ContainerRegistryCredentials object from an AAD Token. A callback can be provided to renew the AAD token when it expires.
 /// <paramref name="aadAccessToken"/> The password for the registry
 /// <paramref name="loginUrl"/> The Azure active directory access token to be used
 /// <paramref name="tenant"/> The tenant of the aad access token (optional)
 /// <paramref name="acquireNewAad"/> Callback function to refresh the <paramref name="aadAccessToken">. Without this parameter, the AAD token cannot be refreshed.
 /// </summary>
 public ContainerRegistryCredentials(string aadAccessToken, string loginUrl, AuthToken.AcquireCallback acquireNewAad = null, CancellationToken cancellationToken = default)
 {
     _mode                     = LoginMode.TokenAad;
     _loginServerUrl           = ProcessLoginUrl(loginUrl);
     _requestCancellationToken = cancellationToken;
     _aadAccess                = new AuthToken(aadAccessToken, acquireNewAad);
     _acrRefresh               = new ContainerRegistryRefreshToken(_aadAccess, _loginServerUrl);
 }
Esempio n. 2
0
        /// <summary>
        /// Construct an ACR access token that refreshes from an ACR refresh token.
        /// </summary>
        /// <param name="acrRefresh"></param>
        /// <param name="scope"></param>
        /// <param name="loginUrl"></param>
        public ContainerRegistryAccessToken(ContainerRegistryRefreshToken refreshToken, string scope, string loginUrl)
        {
            Scope      = scope;
            authClient = new AzureContainerRegistryClient(new TokenCredentials())
            {
                LoginUri = $"https://{loginUrl}"
            };
            string tempRefreshFunction()
            {
                refreshToken.CheckAndRefresh();
                return(authClient.AccessTokens.GetAsync(loginUrl, scope, refreshToken.Value).GetAwaiter().GetResult().AccessTokenProperty);
            };

            // initialize token and refresh function
            InitializeToken(tempRefreshFunction);
        }