Hello @EngincanV, My API versioning problem solved as i followed sample and document both. Now challenge is when generating proxy in my angular application. i am getting errors in "api-version" params. please refer below screen shot. what i have to do to make sure that angular generated service proxy class have no issue.
i have 1 scenario where api method receive request. for ex:
Question: how i can achieve this scenario. Please share document and sample code.
Hi @mliming, this is custom api implementation and this api used by our mobile app. Now challenge is, how to send back token to mobile app so that user can continue in the app.
i am creating new api endpoint which allowes google auth token to be passed as input paramenter. my api method do all business check as per below code to check the token and register the user. Now question is how i can send idenitty auth token back to user so that it can be used with other api calls.
public async Task<string> RegisterExternalUserAsync(string LoginProvider, string token)
{
//ClaimsPrincipal claimsPrincipal = new();
IRestResponse restResponse = new RestResponse();
if (LoginProvider == "Google")
{
var client = new RestClient("https://www.googleapis.com/oauth2/v2/userinfo");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Accept", "application/json");
client.AddDefaultHeader("Authorization", string.Format("Bearer {0}", token));
restResponse = client.Execute(request);
}
if(restResponse == null)
{
return "Invalid Token";
}
CustomUserData data = JsonConvert.DeserializeObject<CustomUserData>(restResponse.Content);
var result = await _signInManager.ExternalLoginSignInAsync(
LoginProvider,
data.id,
isPersistent: true,
bypassTwoFactor: true
);
if (!result.Succeeded)
{
var user = new Volo.Abp.Identity.IdentityUser(GuidGenerator.Create(), data.email, data.email, CurrentTenant.Id);
await _userManager.CreateAsync(user);
await _userManager.AddDefaultRolesAsync(user);
if (!user.EmailConfirmed)
{
var clientUrl = _configuration["App:ClientUrl"];
SendEmailConfirmationTokenDto emailConfirmationTokenDto = new()
{
AppName = "MVC",
Email = data.email,
ReturnUrl = clientUrl
};
await _accountAppService.SendEmailConfirmationTokenAsync(emailConfirmationTokenDto);
}
var userLoginAlreadyExists = user.Logins.Any(x =>
x.TenantId == user.TenantId &&
x.LoginProvider == LoginProvider &&
x.ProviderKey == data.id);
if (!userLoginAlreadyExists)
{
user.AddLogin(new Microsoft.AspNetCore.Identity.UserLoginInfo(
LoginProvider,
data.id,
LoginProvider
)
);
await _userManager.UpdateAsync(user);
}
await _signInManager.SignInAsync(user,true,null);
//TODO: return identity token back to user
}
else
{
var identityUser = await _userManager.FindByEmailAsync(data.email);
await _signInManager.SignInAsync(identityUser, true,null);
//TODO: return identity token back to user
}
return string.Empty;
}
user is not able to login if tenant has enabled email confirmation after user sign-up. As tenant has enabled setting later but user has already signed-up. how we can enable email confirmation process for all existing users?
Question: how to version API. i have done below changes but i am not getting swagger working:
1- Controller changes [RemoteService] [Area("app")] [ApiVersion("2")] [ControllerName("BPMMapping")] [ApiExplorerSettings(IgnoreApi = false)] [Route("api/v{version:apiVersion}/app/bpmmappings")] public class BPMMappingV2Controller : AbpController, IBPMMappingAppService { }
2- Host Module Changes
private static void ConfigureSwagger(ServiceConfigurationContext context, IConfiguration configuration) { context.Services.AddApiVersioning(config => { config.DefaultApiVersion = new ApiVersion(1, 0); config.ReportApiVersions = true; config.AssumeDefaultVersionWhenUnspecified = true; });
context.Services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
options.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;
});
context.Services.AddMvc(options => {
foreach (var outputFormatter in
options.OutputFormatters.OfType<ODataOutputFormatter>().Where(_ => .SupportedMediaTypes.Count == 0)) { outputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.odatatestxx-odata")); } foreach (var inputFormatter in options.InputFormatters.OfType<ODataInputFormatter>().Where( => _.SupportedMediaTypes.Count == 0)) { inputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.odatatestxx-odata")); } }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
context.Services.AddAbpSwaggerGenWithOAuth(
configuration["AuthServer:Authority"],
new Dictionary<string, string>
{
{"EzpandCC", "EzpandCC API"}
},
options =>
{
options.CustomSchemaIds(x => x.FullName);
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo() { Title = "EzpandCC API V1", Version = "v1", Description = "API V1", });
options.SwaggerDoc("v2", new Microsoft.OpenApi.Models.OpenApiInfo() { Title = "EzpandCC API V2", Version = "v2", Description = "API V2", });
options.DocInclusionPredicate((version, desc) =>
{
if (!desc.TryGetMethodInfo(out MethodInfo methodInfo)) return false;
var versions = methodInfo.DeclaringType.GetCustomAttributes(true).OfType<ApiVersionAttribute>().SelectMany(attr => attr.Versions);
var maps = methodInfo.GetCustomAttributes(true).OfType<MapToApiVersionAttribute>().SelectMany(attr => attr.Versions).ToArray();
version = version.Replace("v", "");
return versions.Any(v => v.ToString() == version && maps.Any(v => v.ToString() == version));
});
});
context.Services.RegisterServiceIoc();
}
3- Host Module --> OnApplicationInitialization() changes //----------new start ------------ app.UseSwagger(options => options.RouteTemplate = "swagger/{documentName}/swagger.json"); app.UseSwaggerUI(options => {
options.DocumentTitle = "Aztute API";
options.SwaggerEndpoint($"/swagger/v1/swagger.json", $"v1");
options.SwaggerEndpoint($"/swagger/v2/swagger.json", $"v2");
IConfiguration configuration = context.GetConfiguration();
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
});
app.UseEndpoints(endpoints => endpoints.MapControllers());
//----------new end ------------
//--------- default abp start -----------
//app.UseSwagger();
//app.UseSwaggerUI(options =>
//{
// options.SwaggerEndpoint("/swagger/v1/swagger.json", "EzpandCC API");
// IConfiguration configuration = context.GetConfiguration();
// options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
// options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
//});
4- Swagger response
Hello @Maliming. you are correct. there was some issue with azure service creation. i have created new instance and working as expected.
yes. i have tried that but not working.
Hi Team, How i can use "Azure redis cache" in place of local redis server.