Compare commits

...

2 Commits

Author SHA1 Message Date
2be15b57e8 Add nodejs 2021-03-25 12:04:09 +07:00
29644d15c0 Authentication 2021-03-25 11:21:55 +07:00
13 changed files with 1990 additions and 5 deletions

12
Next/.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
// .gitnignore
# next.js build output
.next
# dotenv environment variables file (build for Zeit Now)
.env
.env.build
# Dependency directories
node_modules/
# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

2
Next/next-env.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
/// <reference types="next" />
/// <reference types="next/types/global" />

1842
Next/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

24
Next/package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "testappruna",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"author": "",
"license": "ISC",
"dependencies": {
"next": "^10.0.9",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@types/node": "^14.14.35",
"@types/react": "^17.0.3",
"typescript": "^4.2.3"
}
}

6
Next/pages/index.tsx Normal file
View File

@ -0,0 +1,6 @@
function Index() {
return (
<p>Hello World</p>
);
}
export default Index;

36
Next/tsconfig.json Normal file
View File

@ -0,0 +1,36 @@
{
"compilerOptions": {
"target": "ES2015",
"module": "ESNext",
"importHelpers": true,
"strict": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noPropertyAccessFromIndexSignature": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"noEmit": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"esModuleInterop": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}

View File

@ -0,0 +1,34 @@
using IdentityModel.Client;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace TestAppRuna.TokenGenerator
{
class Program
{
static void Main(string[] args)
{
Startup().Wait();
}
static async Task Startup()
{
var clientID = "testappruna";
var clientSecret = "1071ccf6-1ea7-4d75-b6e7-28846e386eb5";
var client = new HttpClient();
var disco = await client.GetDiscoveryDocumentAsync("https://accounts.nanao.moe/auth/realms/staging");
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
{
Address = disco.TokenEndpoint,
ClientId = clientID,
ClientSecret = clientSecret,
Scope = "customer-api"
});
Console.WriteLine(response.AccessToken);
}
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityModel" Version="5.0.1" />
</ItemGroup>
</Project>

View File

@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAppRuna", "TestAppRuna\TestAppRuna.csproj", "{07486869-70E3-49C6-8C73-782BFCBD4284}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAppRuna", "TestAppRuna\TestAppRuna.csproj", "{07486869-70E3-49C6-8C73-782BFCBD4284}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAppRuna.Entities", "TestAppRuna.Entities\TestAppRuna.Entities.csproj", "{15F529A1-7CA7-4379-886B-47D1DBDA0AB4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAppRuna.Entities", "TestAppRuna.Entities\TestAppRuna.Entities.csproj", "{15F529A1-7CA7-4379-886B-47D1DBDA0AB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAppRuna.TokenGenerator", "TestAppRuna.TokenGenerator\TestAppRuna.TokenGenerator.csproj", "{31FC0DAE-E09B-4F14-9C1F-2F5A79D76353}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +23,10 @@ Global
{15F529A1-7CA7-4379-886B-47D1DBDA0AB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15F529A1-7CA7-4379-886B-47D1DBDA0AB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15F529A1-7CA7-4379-886B-47D1DBDA0AB4}.Release|Any CPU.Build.0 = Release|Any CPU
{31FC0DAE-E09B-4F14-9C1F-2F5A79D76353}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31FC0DAE-E09B-4F14-9C1F-2F5A79D76353}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31FC0DAE-E09B-4F14-9C1F-2F5A79D76353}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31FC0DAE-E09B-4F14-9C1F-2F5A79D76353}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
@ -13,6 +14,7 @@ namespace TestAppRuna.API
{
[Route("api/[controller]")]
[ApiController]
[Authorize(AuthenticationSchemes = "nanaoaccounts")]
public class CustomerController : ControllerBase
{
public CustomerController(ShopDbContext shopDbContext)

BIN
TestAppRuna/Shop.slite.db Normal file

Binary file not shown.

View File

@ -44,7 +44,13 @@ namespace TestAppRuna
options.UseSqlite(Configuration.GetConnectionString("ShopDB"));
});
services.AddSwaggerDocument();
services.AddAuthentication()
.AddJwtBearer("nanaoaccounts", options =>
{
options.Authority = "https://accounts.nanao.moe/auth/realms/staging";
options.Audience = "testappruna";
}
);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -76,13 +82,15 @@ namespace TestAppRuna
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}

View File

@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.4" />
<PackageReference Include="NSwag.AspNetCore" Version="13.10.8" />
<PackageReference Include="Serilog.AspNetCore" Version="4.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />