Skip to content

Commit

Permalink
web test project
Browse files Browse the repository at this point in the history
  • Loading branch information
djordjedjukic committed Feb 5, 2021
1 parent 8acaec6 commit df5ad47
Show file tree
Hide file tree
Showing 56 changed files with 40,208 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Digitalis.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Digitalis", "Digitalis\Digitalis.csproj", "{8D54E4BE-2666-44EF-A3EB-65AEF2811CF8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Specs", "Specs\Specs.csproj", "{F7D140B3-4B40-4544-8941-83B67A73F69D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Specs", "Specs\Specs.csproj", "{F7D140B3-4B40-4544-8941-83B67A73F69D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebTest", "WebTest\WebTest.csproj", "{77D51649-A908-41EE-A1FE-ED415CE7273E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,6 +23,10 @@ Global
{F7D140B3-4B40-4544-8941-83B67A73F69D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7D140B3-4B40-4544-8941-83B67A73F69D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7D140B3-4B40-4544-8941-83B67A73F69D}.Release|Any CPU.Build.0 = Release|Any CPU
{77D51649-A908-41EE-A1FE-ED415CE7273E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77D51649-A908-41EE-A1FE-ED415CE7273E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77D51649-A908-41EE-A1FE-ED415CE7273E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77D51649-A908-41EE-A1FE-ED415CE7273E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/Digitalis/Features/CreateEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Auth(IHttpContextAccessor ctx, IDocumentSession session) : base(ctx, sess

public override void Authorize(Command request)
{
AuthorizationGuard.AffirmClaim(User, AppClaims.CreateNewEntry);
//AuthorizationGuard.AffirmClaim(User, AppClaims.CreateNewEntry);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Digitalis/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void ConfigureServices(IServiceCollection services)
{
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(jwt => jwt.UseGoogle(clientId: "client_id"));
.AddJwtBearer(jwt => jwt.UseGoogle(clientId: "862194400783-128gj3m1j52gs6lrl6ueeehtgaiqq8q8.apps.googleusercontent.com"));

services.AddHealthChecks();
services.AddControllers();
Expand Down
91 changes: 91 additions & 0 deletions src/WebTest/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using WebTest.Models;

namespace WebTest.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index(string entryId)
{
return View(entryId);
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}

public IActionResult GoogleAuth()
{
return Redirect("https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=https://localhost:44366/home/authentication&prompt=consent&response_type=code&client_id=862194400783-128gj3m1j52gs6lrl6ueeehtgaiqq8q8.apps.googleusercontent.com&scope=profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&access_type=offline");
}

public IActionResult Authentication(string code)
{
using (var client = new HttpClient())
{
var jwtToken = GetGoogleToken(code, client);

if (!string.IsNullOrEmpty(jwtToken))
{
var newEntry = new
{
tags = new string[] { "chess", "formula1" }

};

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);

var responseCreateEntry = client.PostAsJsonAsync("http://localhost:51665/entry", newEntry).Result;

if (responseCreateEntry.IsSuccessStatusCode)
{
//var createdEntryId = responseCreateEntry.Content.ReadFromJsonAsync<string>().Result;
//ViewBag.CreatedEntryId = createdEntryId;
}
}
}

return View("Index");
}

private string GetGoogleToken(string code, HttpClient client)
{
var payload = new
{
code = code,
grant_type = "authorization_code",
client_id = "862194400783-128gj3m1j52gs6lrl6ueeehtgaiqq8q8.apps.googleusercontent.com",
client_secret = "DSSIWDRHxViWR8ssUCLd1WaC",
redirect_uri = "https://localhost:44366/home/authentication"
};

var responseGoogleAuth = client.PostAsJsonAsync("https://oauth2.googleapis.com/token", payload).Result;

if (responseGoogleAuth.IsSuccessStatusCode)
{
var authData = responseGoogleAuth.Content.ReadFromJsonAsync<GoogleAuthData>().Result;
return authData.id_token;
}
return "";
}
}
}
11 changes: 11 additions & 0 deletions src/WebTest/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace WebTest.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
21 changes: 21 additions & 0 deletions src/WebTest/Models/GoogleAuthData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace WebTest.Models
{
public class GoogleAuthData
{
public string id_token { get; set; }
}

public class GoogleAuthRequest
{
public string code { get; set; }

public string grant_type { get; set; }

public string client_id { get; set; }

public string client_secret { get; set; }

public string redirect_uri { get; set; }

}
}
26 changes: 26 additions & 0 deletions src/WebTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebTest
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
28 changes: 28 additions & 0 deletions src/WebTest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63657",
"sslPort": 44366
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebTest": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
58 changes: 58 additions & 0 deletions src/WebTest/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebTest
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
8 changes: 8 additions & 0 deletions src/WebTest/Views/Home/Entries.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@{
ViewData["Title"] = "Entries";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
15 changes: 15 additions & 0 deletions src/WebTest/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@{
ViewData["Title"] = "Home Page";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>


<input type="button" class="btn btn-primary" title="Delete" value="Continue with Google" onclick="location.href='@Url.Action("GoogleAuth", "Home")'" />


<h1>@ViewBag.CreatedEntryId</h1>

</div>
6 changes: 6 additions & 0 deletions src/WebTest/Views/Home/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
25 changes: 25 additions & 0 deletions src/WebTest/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
48 changes: 48 additions & 0 deletions src/WebTest/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebTest</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">WebTest</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2021 - WebTest - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
2 changes: 2 additions & 0 deletions src/WebTest/Views/Shared/_ValidationScriptsPartial.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
3 changes: 3 additions & 0 deletions src/WebTest/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using WebTest
@using WebTest.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions src/WebTest/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
Loading

0 comments on commit df5ad47

Please sign in to comment.