Answer the question
In order to leave comments, you need to log in
Authentication via VK in asp.net core web api. How to implement correctly?
I am writing an application. The server part is a web api on asp.net core, and the client part is a vuejs application. My task is to implement a user login to the site through VKontakte.
The backend uses the AspNet.Security.OAuth.Vkontakte package .
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication()
.AddVkontakte(builder =>
{
builder.ApiVersion = "5.130";
builder.ClientId = Configuration["ClientId"];
builder.ClientSecret = Configuration["SecureKey"];
builder.AuthorizationEndpoint = "https://oauth.vk.com/authorize";
builder.TokenEndpoint = "https://oauth.vk.com/access_token";
builder.Scope.Add("friends");
builder.Scope.Add("offline");
});
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "WeAgree", Version = "v1" });
});
}
Answer the question
In order to leave comments, you need to log in
Generate a jwt token on the server side.
Further, this vue token is hawked in local.storage and in the http interceptor constantly puts this token in the request. Handler on the bark, each request listens and checks the embedded token from the client for validity. Throws standard errors 400 and 401 if the token is not valid or has already timed out.
Everything is pretty standard.
For self-learning purposes, implement authentication with your api and your login password, without using the vk api. As soon as everything works, then connect VK api.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question