Hi,
I am using Microsoft.EntityFrameworkCore (Version 8.0.6) + Microsoft.AspNetCore.Identity.EntityFrameworkCore(Version 8.0.6) + Npgsql.EntityFrameworkCore.PostgreSQL (Version 8).
I want to get refresh token which it is automatically generated by Identity Framework. After I retrieve that token, i want to save in database.
Here sample startup.cs file,
sing Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyModel;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;
using AutoMapper;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.AspNetCore.Identity.UI.Services;
using Npgsql;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var builder = WebApplication.CreateBuilder(args);
var allowAllOrigins = "AllowAllOriginsPolicy";
builder.Services.AddCors(options =>
{
options.AddPolicy(allowAllOrigins,
policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Name = "Authorization",
Type = SecuritySchemeType.ApiKey
});
options.OperationFilter
});
builder.Services.AddAutoMapper(cfg =>
{
cfg.CreateMap
});
var dataSourceBuilderSource = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("DefaultConnection"));
dataSourceBuilderSource.EnableDynamicJson();
var dataSourceBuilder = dataSourceBuilderSource.Build();
builder.Services.AddDbContext
options.UseNpgsql(dataSourceBuilder);
});
builder.Services.AddAuthorization();
builder.Services.AddIdentityApiEndpoints
.AddRoles
.AddEntityFrameworkStores
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped
builder.Services.AddScoped
builder.Services.AddSingleton
builder.Services.RegisterAccountModule();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var applicationDbContext = scope.ServiceProvider.GetRequiredService
applicationDbContext.Database.Migrate();
}
app.UseSwagger();
app.UseSwaggerUI();
app.MapIdentityApi
app.UseHttpsRedirection();
app.UseCors(allowAllOrigins);
app.UseAuthorization();
app.MapEndpoints();
app.Run();
Note: The above configuration will auto provide access and refresh token and have it in internal storage. I want to get that token and wants to store in database.