diff --git a/Demo1/Demo1.sln b/Demo1/Demo1.sln new file mode 100644 index 0000000000000000000000000000000000000000..20ff3a0189ac3b4a486181e74f2cb95f61957e50 --- /dev/null +++ b/Demo1/Demo1.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32414.318 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo1", "Demo1\Demo1.csproj", "{7779B267-9E74-466B-8396-AB6BDB32F989}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7779B267-9E74-466B-8396-AB6BDB32F989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7779B267-9E74-466B-8396-AB6BDB32F989}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7779B267-9E74-466B-8396-AB6BDB32F989}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7779B267-9E74-466B-8396-AB6BDB32F989}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {49EACB24-B2ED-4443-B751-29FDE6405270} + EndGlobalSection +EndGlobal diff --git a/Demo1/Demo1/Demo1.csproj b/Demo1/Demo1/Demo1.csproj new file mode 100644 index 0000000000000000000000000000000000000000..bd5a14502891a6b9583859b7cdd709610d6ffa90 --- /dev/null +++ b/Demo1/Demo1/Demo1.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + diff --git a/Demo1/Demo1/Program.cs b/Demo1/Demo1/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..84716648e40102ff81ad294b324e787d4c6c14ed --- /dev/null +++ b/Demo1/Demo1/Program.cs @@ -0,0 +1,45 @@ +using Microsoft.Identity.Client; +using Flurl.Http; +using Flurl; + +// See https://aka.ms/new-console-template for more +string _clientId = "89924e36-f70a-43c3-86c5-51bc7b5e8136"; +string _tenantId = "453d8628-343d-48b9-b4d9-c0a97e4be3b7"; +string endpoint = "https://login.microsoftonline.com/common/oauth2/authorize"; +var app = PublicClientApplicationBuilder +.Create(_clientId) +.WithAuthority(AzureCloudInstance.AzurePublic, _tenantId) +.WithRedirectUri("http://localhost") +.Build(); + +string[] scopes = new string[] +{ + "https://management.azure.com/user_impersonation" +}; + +var accounts = await app.GetAccountsAsync(); + + var account = accounts.FirstOrDefault(); + + var resS = await app.AcquireTokenSilent(scopes, account).ExecuteAsync(); + +AuthenticationResult res = await app.AcquireTokenInteractive(scopes).ExecuteAsync(); + +Console.WriteLine(res.AccessToken, res.AuthenticationResultMetadata); + + +var tokenReq = new Url("https://login.microsoftonline.com/common/oauth2/authorize") + .SetQueryParams(new Dictionary + { + ["client_id"] = _clientId + }); + +var req = new Url("https://management.azure.com/subscriptions/219b2431-594f-47fa-8e85-664196aa3f92") + .AppendPathSegment("resources") + .WithOAuthBearerToken(res.AccessToken) + .SetQueryParam("api-version", "2021-04-01"); + +//var response = tokenReq.GetStringAsync().Result; +var response = req.GetJsonAsync().Result; + +Console.WriteLine(response); diff --git a/azure_back/azure_back.sln b/azure_back/azure_back.sln new file mode 100644 index 0000000000000000000000000000000000000000..40a41a03dcd397c01062d361cee8037140c44d1e --- /dev/null +++ b/azure_back/azure_back.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32414.318 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "azure_back", "azure_back\azure_back.csproj", "{7638958D-CD1A-4411-9CB3-77BFB9EE0BDB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7638958D-CD1A-4411-9CB3-77BFB9EE0BDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7638958D-CD1A-4411-9CB3-77BFB9EE0BDB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7638958D-CD1A-4411-9CB3-77BFB9EE0BDB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7638958D-CD1A-4411-9CB3-77BFB9EE0BDB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E0BD79AE-CD1E-4B35-BFE3-ABADBE803F01} + EndGlobalSection +EndGlobal diff --git a/azure_back/azure_back/Controllers/ResourcesController.cs b/azure_back/azure_back/Controllers/ResourcesController.cs new file mode 100644 index 0000000000000000000000000000000000000000..d09d069a35a17e1b9b0e8fa239980b7ccda8d177 --- /dev/null +++ b/azure_back/azure_back/Controllers/ResourcesController.cs @@ -0,0 +1,6 @@ +namespace azure_back.Controllers +{ + public class ResourcesController + { + } +} diff --git a/azure_back/azure_back/Controllers/WeatherForecastController.cs b/azure_back/azure_back/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000000000000000000000000000000000000..25bfe6d160b68fd71cade3bbabeeed3b8837b216 --- /dev/null +++ b/azure_back/azure_back/Controllers/WeatherForecastController.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.Mvc; + +namespace azure_back.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} \ No newline at end of file diff --git a/azure_back/azure_back/Program.cs b/azure_back/azure_back/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..df2434ce317e34820ce9ff7772e5e9ae829eabf8 --- /dev/null +++ b/azure_back/azure_back/Program.cs @@ -0,0 +1,23 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/azure_back/azure_back/Properties/launchSettings.json b/azure_back/azure_back/Properties/launchSettings.json new file mode 100644 index 0000000000000000000000000000000000000000..09613219a6696dbb9d52f80086f82bea373093df --- /dev/null +++ b/azure_back/azure_back/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:9543", + "sslPort": 0 + } + }, + "profiles": { + "azure_back": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5039", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/azure_back/azure_back/WeatherForecast.cs b/azure_back/azure_back/WeatherForecast.cs new file mode 100644 index 0000000000000000000000000000000000000000..2a2223e13f753ec7161300c3b7121bcf635701c5 --- /dev/null +++ b/azure_back/azure_back/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace azure_back +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/azure_back/azure_back/appsettings.Development.json b/azure_back/azure_back/appsettings.Development.json new file mode 100644 index 0000000000000000000000000000000000000000..0c208ae9181e5e5717e47ec1bd59368aebc6066e --- /dev/null +++ b/azure_back/azure_back/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/azure_back/azure_back/appsettings.json b/azure_back/azure_back/appsettings.json new file mode 100644 index 0000000000000000000000000000000000000000..10f68b8c8b4f796baf8ddeee7551b6a52b9437cc --- /dev/null +++ b/azure_back/azure_back/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/azure_back/azure_back/azure_back.csproj b/azure_back/azure_back/azure_back.csproj new file mode 100644 index 0000000000000000000000000000000000000000..60bf9ead830c6d0b325cbe4e38b3c35311d81282 --- /dev/null +++ b/azure_back/azure_back/azure_back.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + +