internal override async Task AuthenticateAsync(HttpRequestMessage request, HttpResponseMessage response)
        {
            foreach (var header in response.Headers.WwwAuthenticate)
            {
                if (header.Scheme == "Bearer")
                {
                    //Get the bearer bits
                    var bearerBits = AuthenticateParser.ParseTyped(header.Parameter);

                    //Get the token
                    var token = await _client.GetTokenAsync(bearerBits.Realm, bearerBits.Service, bearerBits.Scope);

                    var tokenHandler = new JwtSecurityTokenHandler();

                    var parsed = tokenHandler.ReadJwtToken(token.AccessToken);

                    foreach (var payloadItem in parsed.Payload)
                    {
                        Console.WriteLine($" {payloadItem.Key}: {payloadItem.Value}");
                    }

                    //Set the header
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.Token);

                    return;
                }
            }

            throw new InvalidOperationException("No WWW-Authenticate challenge was found.");
        }
Example #2
0
        internal override async Task AuthenticateAsync(HttpRequestMessage request, HttpResponseMessage response)
        {
            foreach (var header in response.Headers.WwwAuthenticate)
            {
                if (header.Scheme == "Bearer")
                {
                    //Get the bearer bits
                    var bearerBits = AuthenticateParser.ParseTyped(header.Parameter);

                    string scope = bearerBits.Scope;

                    //if (scope == "registry:catalog:*")
                    //{
                    //    scope = "registry:catalog:get";
                    //}

                    //Get the token
                    var token = await _client.GetTokenAsync(bearerBits.Realm, bearerBits.Service, scope, _username, _password);

                    //Console.WriteLine(token.AccessToken);

                    //Set the header
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.Token);

                    return;
                }
            }

            throw new InvalidOperationException("No WWW-Authenticate challenge was found.");
        }
        public override async Task AuthenticateAsync(
            HttpRequestMessage request,
            HttpResponseMessage response)
        {
            var header = this.TryGetSchemaHeader(response, Schema);

            //Get the bearer bits
            var bearerBits = AuthenticateParser.ParseTyped(header.Parameter);

            //Get the token
            var token = await this._client.GetTokenAsync(
                bearerBits.Realm,
                bearerBits.Service,
                bearerBits.Scope);

            //Set the header
            request.Headers.Authorization = new AuthenticationHeaderValue(Schema, token.Token);
        }
Example #4
0
        internal override async Task AuthenticateAsync(HttpRequestMessage request, HttpResponseMessage response)
        {
            foreach (var header in response.Headers.WwwAuthenticate)
            {
                if (header.Scheme == "Bearer")
                {
                    //Get the bearer bits
                    var bearerBits = AuthenticateParser.ParseTyped(header.Parameter);

                    //Get the token
                    var token = await _client.GetTokenAsync(bearerBits.Realm, bearerBits.Service, bearerBits.Scope);

                    //Set the header
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.Token);

                    return;
                }
            }

            throw new InvalidOperationException("No WWW-Authenticate challenge was found.");
        }