forked from MDCPS/DamageAssessment_Backend
		
	Added Azure sql setup for User access micro service
This commit is contained in:
		| @ -2,6 +2,7 @@ | ||||
| using DamageAssesment.Api.DocuLinks.Interfaces; | ||||
| using DamageAssesment.Api.DocuLinks.Models; | ||||
| using DamageAssesment.Api.DocuLinks.Providers; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| @ -24,6 +25,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// Get all Doculink type. | ||||
|         /// </summary> | ||||
|         [HttpGet] | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [Route("doculinks/types")] | ||||
|         [Route("doculinks/types/{language:alpha}")] | ||||
|         public async Task<IActionResult> GetLinkTypesAsync(string? language) | ||||
| @ -38,6 +40,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// <summary> | ||||
|         /// Get a Doculink type by id. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [HttpGet] | ||||
|         [Route("doculinks/types/{id}")] | ||||
|         [Route("doculinks/types/{id}/{language:alpha}")] | ||||
| @ -53,6 +56,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// <summary> | ||||
|         /// Update a existing Doculink type. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [HttpPut] | ||||
|         [Route("doculinks/types/{id}")] | ||||
|         public async Task<IActionResult> UpdateLinkType(int id,Models.LinkType linkType) | ||||
| @ -74,6 +78,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// <summary> | ||||
|         /// Create a new Doculink type. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [HttpPost] | ||||
|         [Route("doculinks/types")] | ||||
|         public async Task<IActionResult> CreateLinkType(Models.LinkType linkType) | ||||
| @ -92,6 +97,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// <summary> | ||||
|         /// Delete a  existing Doculink type by id. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [HttpDelete] | ||||
|         [Route("doculinks/types/{id}")] | ||||
|         public async Task<IActionResult> DeleteLinkType(int id) | ||||
| @ -104,9 +110,10 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|             return NotFound(); | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// Get all Doculink. | ||||
|         /// Get all documents. | ||||
|         /// </summary> | ||||
|         ///  | ||||
|          | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [Route("doculinks")] | ||||
|         [Route("doculinks/{linktype:alpha}")] | ||||
|         [Route("doculinks/{linktype:alpha}/{language:alpha}")] | ||||
| @ -140,6 +147,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// <summary> | ||||
|         /// Get a Doculink by id. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [HttpGet] | ||||
|         [Route("doculinks/{id}")] | ||||
|         [Route("doculinks/{id}/{linktype:alpha}")] | ||||
| @ -156,6 +164,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// <summary> | ||||
|         /// update existing doclink. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [HttpPut] | ||||
|         [Route("doculinks/{id}")] | ||||
|         public async Task<IActionResult> UpdateDocument(int id,ReqDoculink documentInfo) | ||||
| @ -181,6 +190,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// <summary> | ||||
|         /// Create new doclink. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [HttpPost] | ||||
|         [Route("doculinks")] | ||||
|         public async Task<IActionResult> CreateDocument(ReqDoculink documentInfo) | ||||
| @ -208,6 +218,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers | ||||
|         /// <summary> | ||||
|         /// Delete Doculink by id. | ||||
|         /// </summary> | ||||
|         [Authorize(Roles = "admin")] | ||||
|         [HttpDelete] | ||||
|         [Route("doculinks/{id}")] | ||||
|         public async Task<IActionResult> DeleteDocument(int id) | ||||
|  | ||||
| @ -10,6 +10,7 @@ | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> | ||||
|     <PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.21" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" /> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" /> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9"> | ||||
|  | ||||
| @ -2,19 +2,69 @@ using DamageAssesment.Api.DocuLinks.Db; | ||||
| using DamageAssesment.Api.DocuLinks.Interfaces; | ||||
| using DamageAssesment.Api.DocuLinks.Providers; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.AspNetCore.Authentication.JwtBearer; | ||||
| using Microsoft.IdentityModel.Tokens; | ||||
| using System.Reflection; | ||||
| using System.Text; | ||||
| using Microsoft.OpenApi.Models; | ||||
|  | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
|  | ||||
| // Add services to the container. | ||||
|  | ||||
| var authkey = builder.Configuration.GetValue<string>("JwtSettings:securitykey"); | ||||
| builder.Services.AddAuthentication(item => | ||||
| { | ||||
|     item.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | ||||
|     item.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | ||||
| }).AddJwtBearer(item => | ||||
| { | ||||
|     item.RequireHttpsMetadata = true; | ||||
|     item.SaveToken = true; | ||||
|     item.TokenValidationParameters = new TokenValidationParameters() | ||||
|     { | ||||
|         ValidateIssuerSigningKey = true, | ||||
|         IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(authkey)), | ||||
|         ValidateIssuer = false, | ||||
|         ValidateAudience = false, | ||||
|         ClockSkew = TimeSpan.Zero | ||||
|     }; | ||||
| }); | ||||
| builder.Services.AddControllers(); | ||||
| builder.Services.AddSwaggerGen(c => | ||||
| builder.Services.AddSwaggerGen(options => | ||||
| { | ||||
|     // Include XML comments from your assembly | ||||
|     var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; | ||||
|     var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); | ||||
|     c.IncludeXmlComments(xmlPath); | ||||
|     options.IncludeXmlComments(xmlPath); | ||||
|  | ||||
|     OpenApiSecurityScheme securityDefinition = new OpenApiSecurityScheme() | ||||
|     { | ||||
|         Name = "Bearer", | ||||
|         BearerFormat = "JWT", | ||||
|         Scheme = "bearer", | ||||
|         Description = "Specify the authorization token.", | ||||
|         In = ParameterLocation.Header, | ||||
|         Type = SecuritySchemeType.Http, | ||||
|     }; | ||||
|  | ||||
|     options.AddSecurityDefinition("jwt_auth", securityDefinition); | ||||
|  | ||||
|     // Make sure swagger UI requires a Bearer token specified | ||||
|     OpenApiSecurityScheme securityScheme = new OpenApiSecurityScheme() | ||||
|     { | ||||
|         Reference = new OpenApiReference() | ||||
|         { | ||||
|             Id = "jwt_auth", | ||||
|             Type = ReferenceType.SecurityScheme | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     OpenApiSecurityRequirement securityRequirements = new OpenApiSecurityRequirement() | ||||
|     { | ||||
|         {securityScheme, new string[] { }}, | ||||
|     }; | ||||
|  | ||||
|     options.AddSecurityRequirement(securityRequirements); | ||||
| }); | ||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| @ -36,6 +86,7 @@ if (app.Environment.IsDevelopment()) | ||||
|     app.UseSwaggerUI(); | ||||
| } | ||||
|  | ||||
| app.UseAuthentication(); | ||||
| app.UseAuthorization(); | ||||
|  | ||||
| app.MapControllers(); | ||||
|  | ||||
| @ -14,7 +14,7 @@ | ||||
|       "dotnetRunMessages": true, | ||||
|       "launchBrowser": true, | ||||
|       "launchUrl": "swagger", | ||||
|       "applicationUrl": "http://localhost:5133", | ||||
|       "applicationUrl": "http://localhost:5136", | ||||
|       "environmentVariables": { | ||||
|         "ASPNETCORE_ENVIRONMENT": "Development" | ||||
|       } | ||||
|  | ||||
| @ -1,4 +1,7 @@ | ||||
| { | ||||
|   "JwtSettings": { | ||||
|     "securitykey": "bWlhbWkgZGFkZSBzY2hvb2xzIHNlY3JldCBrZXk=" | ||||
|   }, | ||||
|   "Logging": { | ||||
|     "LogLevel": { | ||||
|       "Default": "Information", | ||||
|  | ||||
		Reference in New Issue
	
	Block a user