Basic Token Authentication with C# API 2

I want to Secure Web API 2 with Token Authentication .All the tutorial is all about user name and password but i am calling api without user name and password example https://api/employee/ is my client path and putting [Authorize] on Api it is showing authorisation denied how to implement it with token authentication?

var authorizationHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes("rajeev:secretKey"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authorizationHeader);

    var form = new Dictionary<string, string>  
               {"grant_type", "password"},  
               {"username", "rranjan"},  
               {"password", "password@123"},  

    var tokenResponse = client.PostAsync(baseAddress + "accesstoken", new FormUrlEncodedContent(form)).Result;  
    var token = tokenResponse.Content.ReadAsAsync<Token>(new[] { new JsonMediaTypeFormatter() }).Result;  

    Console.WriteLine("Token issued is: {0}", token.AccessToken);  

I do not need to authenticate user with user name and password example this link and in header you will get a key is securing it press Ctrl + U and whenever you will open it in new tab you will get different key.i need exactly this.

Started by englishsassy at May 12, 2019 - 11:45 PM