mirror of
https://github.com/ditkrg/AuthorizationServerDemos.git
synced 2026-01-23 03:36:52 +00:00
Merge branch 'master' of https://github.com/ditdevtools/AuthorizationServerDemos
This commit is contained in:
commit
3f5493d896
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<PackageReference Include="TwoStepsAuthenticator" Version="1.4.1" />
|
<PackageReference Include="TwoStepsAuthenticator" Version="1.4.1" />
|
||||||
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.11" />
|
||||||
<PackageReference Include="Westwind.AspNetCore.LiveReload" Version="0.3.1" />
|
<PackageReference Include="Westwind.AspNetCore.LiveReload" Version="0.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -82,9 +82,8 @@ namespace OidcSamples.AuthorizationServer
|
|||||||
RequirePkce = true,
|
RequirePkce = true,
|
||||||
PostLogoutRedirectUris =
|
PostLogoutRedirectUris =
|
||||||
{
|
{
|
||||||
"http://localhost:3000/signout-callback-oidc"
|
"http://localhost:3000"
|
||||||
},
|
},
|
||||||
|
|
||||||
RequireConsent = false,
|
RequireConsent = false,
|
||||||
},
|
},
|
||||||
new Client
|
new Client
|
||||||
@ -113,9 +112,8 @@ namespace OidcSamples.AuthorizationServer
|
|||||||
RequirePkce = true,
|
RequirePkce = true,
|
||||||
PostLogoutRedirectUris =
|
PostLogoutRedirectUris =
|
||||||
{
|
{
|
||||||
"http://localhost:4000/signout-callback-oidc"
|
"http://localhost:4000"
|
||||||
},
|
},
|
||||||
|
|
||||||
RequireConsent = false,
|
RequireConsent = false,
|
||||||
},
|
},
|
||||||
new Client
|
new Client
|
||||||
@ -148,7 +146,8 @@ namespace OidcSamples.AuthorizationServer
|
|||||||
{
|
{
|
||||||
"http://localhost:7000/signout-callback-oidc"
|
"http://localhost:7000/signout-callback-oidc"
|
||||||
},
|
},
|
||||||
|
FrontChannelLogoutUri = "http://localhost:7000/signout-callback-oidc",
|
||||||
|
FrontChannelLogoutSessionRequired = true,
|
||||||
RequireConsent = false,
|
RequireConsent = false,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -241,7 +241,14 @@ namespace IdentityServerHost.Quickstart.UI
|
|||||||
return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
|
return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
return View("LoggedOut", vm);
|
if (string.IsNullOrEmpty(vm.PostLogoutRedirectUri))
|
||||||
|
{
|
||||||
|
return View("LoggedOut", vm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Redirect(vm.PostLogoutRedirectUri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
|||||||
@ -11,9 +11,9 @@ namespace OidcSamples.TaxApp.Pages
|
|||||||
{
|
{
|
||||||
public enum VehicleType
|
public enum VehicleType
|
||||||
{
|
{
|
||||||
Sedan = 0,
|
Sedan = 1,
|
||||||
SUV = 1,
|
SUV = 2,
|
||||||
Pickup = 2
|
Pickup = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Vehicle
|
public class Vehicle
|
||||||
|
|||||||
@ -16,9 +16,9 @@ namespace OidcSamples.TrafficPoliceApi.Data
|
|||||||
|
|
||||||
public enum VehicleType
|
public enum VehicleType
|
||||||
{
|
{
|
||||||
Sedan = 0,
|
Sedan = 1,
|
||||||
SUV = 1,
|
SUV = 2,
|
||||||
Pickup = 2
|
Pickup = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Vehicle
|
public class Vehicle
|
||||||
|
|||||||
@ -8,7 +8,10 @@ const pool = new Pool({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const getAllRealEstate = (request, response) => {
|
const getAllRealEstate = (request, response) => {
|
||||||
pool.query("SELECT * FROM real_estate ORDER BY id DESC", (error, results) => {
|
// The express-jwt middleware decodes the jwt token and store all claims on request.user
|
||||||
|
// https://github.com/auth0/express-jwt/issues/153#issuecomment-269498310
|
||||||
|
citizen_upn = request.user.sub;
|
||||||
|
pool.query(`SELECT * FROM real_estate WHERE citizen_upn = '${citizen_upn}' ORDER BY id DESC`, (error, results) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@ -16,10 +19,10 @@ const getAllRealEstate = (request, response) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// We don't need the citizen_upn here? ** Temporary **
|
|
||||||
const insertRealEstate = (request, response) => {
|
const insertRealEstate = (request, response) => {
|
||||||
const { address, area, citizen_upn } = request.body;
|
const { address, area } = request.body;
|
||||||
|
citizen_upn = request.user.sub;
|
||||||
|
console.log(citizen_upn)
|
||||||
pool.query(
|
pool.query(
|
||||||
"INSERT INTO real_estate (address, area, citizen_upn) VALUES ($1, $2, $3)",
|
"INSERT INTO real_estate (address, area, citizen_upn) VALUES ($1, $2, $3)",
|
||||||
[address, area, citizen_upn],
|
[address, area, citizen_upn],
|
||||||
|
|||||||
@ -14,7 +14,7 @@ We are using IdentityServer 4 to implement our Authorization Server. You can fin
|
|||||||
|
|
||||||
**Dependencies:**
|
**Dependencies:**
|
||||||
|
|
||||||
- [.NET 5 SDK](https://dotnet.microsoft.com/download/dotnet/5.0)
|
- [.NET Core 3.1 SDK](https://dotnet.microsoft.com/download/dotnet-core/3.1) (Because the latest version that IdentityServer4 supports is .NET Core 3.1)
|
||||||
|
|
||||||
**How to run:**
|
**How to run:**
|
||||||
|
|
||||||
|
|||||||
@ -14,8 +14,8 @@ const Navbar = () => {
|
|||||||
|
|
||||||
const user = useSelector((state) => state.auth.user);
|
const user = useSelector((state) => state.auth.user);
|
||||||
|
|
||||||
function signOut() {
|
async function signOut() {
|
||||||
signoutRedirect();
|
await signoutRedirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -21,7 +21,7 @@ const VehicleRegisterForm = () => {
|
|||||||
|
|
||||||
async function registerVehicle() {
|
async function registerVehicle() {
|
||||||
await apiService.registerVehicle(
|
await apiService.registerVehicle(
|
||||||
{ address, area, citizen_upn: user.profile.sub },
|
{ address, area },
|
||||||
user.access_token
|
user.access_token
|
||||||
);
|
);
|
||||||
history.push("/");
|
history.push("/");
|
||||||
|
|||||||
@ -11,7 +11,6 @@ const Table = ({ vehicleData }) => {
|
|||||||
<tr>
|
<tr>
|
||||||
<ColumnName text={"Address"} />
|
<ColumnName text={"Address"} />
|
||||||
<ColumnName text={"Area"} />
|
<ColumnName text={"Area"} />
|
||||||
<ColumnName text={"Citizen UPN"} />
|
|
||||||
<th scope="col" className="relative px-6 py-3">
|
<th scope="col" className="relative px-6 py-3">
|
||||||
<span className="sr-only">Actions</span>
|
<span className="sr-only">Actions</span>
|
||||||
</th>
|
</th>
|
||||||
@ -22,7 +21,6 @@ const Table = ({ vehicleData }) => {
|
|||||||
<tr key={vehicle.id} className="bg-gray-50">
|
<tr key={vehicle.id} className="bg-gray-50">
|
||||||
<TableData text={vehicle.address} />
|
<TableData text={vehicle.address} />
|
||||||
<TableData text={vehicle.area} />
|
<TableData text={vehicle.area} />
|
||||||
<TableData text={vehicle.citizen_upn} />
|
|
||||||
<TableData Component={EditBtns} />
|
<TableData Component={EditBtns} />
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const config = {
|
|||||||
redirect_uri: "http://localhost:4000/signin-oidc",
|
redirect_uri: "http://localhost:4000/signin-oidc",
|
||||||
response_type: "code",
|
response_type: "code",
|
||||||
scope: "openid profile real-estate-api",
|
scope: "openid profile real-estate-api",
|
||||||
post_logout_redirect_uri: "http://localhost:4000/signout-oidc",
|
post_logout_redirect_uri: "http://localhost:4000",
|
||||||
};
|
};
|
||||||
|
|
||||||
const userManager = new UserManager(config);
|
const userManager = new UserManager(config);
|
||||||
@ -33,10 +33,14 @@ export function signinRedirectCallback() {
|
|||||||
return userManager.signinRedirectCallback();
|
return userManager.signinRedirectCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function signoutRedirect() {
|
export async function signoutRedirect() {
|
||||||
|
var user = await userManager.getUser();
|
||||||
|
let id_token = null;
|
||||||
|
if (user) id_token = user.id_token;
|
||||||
|
|
||||||
userManager.clearStaleState();
|
userManager.clearStaleState();
|
||||||
userManager.removeUser();
|
userManager.removeUser();
|
||||||
return userManager.signoutRedirect();
|
return userManager.signoutRedirect({ id_token_hint: id_token });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function signoutRedirectCallback() {
|
export function signoutRedirectCallback() {
|
||||||
|
|||||||
@ -14,8 +14,8 @@ const Navbar = () => {
|
|||||||
|
|
||||||
const user = useSelector((state) => state.auth.user);
|
const user = useSelector((state) => state.auth.user);
|
||||||
|
|
||||||
function signOut() {
|
async function signOut() {
|
||||||
signoutRedirect();
|
await signoutRedirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const config = {
|
|||||||
redirect_uri: "http://localhost:3000/signin-oidc",
|
redirect_uri: "http://localhost:3000/signin-oidc",
|
||||||
response_type: "code",
|
response_type: "code",
|
||||||
scope: "openid profile traffic-police-api",
|
scope: "openid profile traffic-police-api",
|
||||||
post_logout_redirect_uri: "http://localhost:3000/signout-oidc",
|
post_logout_redirect_uri: "http://localhost:3000"
|
||||||
};
|
};
|
||||||
|
|
||||||
const userManager = new UserManager(config);
|
const userManager = new UserManager(config);
|
||||||
@ -33,10 +33,14 @@ export function signinRedirectCallback() {
|
|||||||
return userManager.signinRedirectCallback();
|
return userManager.signinRedirectCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function signoutRedirect() {
|
export async function signoutRedirect() {
|
||||||
|
var user = await userManager.getUser();
|
||||||
|
let id_token = null;
|
||||||
|
if (user) id_token = user.id_token;
|
||||||
|
|
||||||
userManager.clearStaleState();
|
userManager.clearStaleState();
|
||||||
userManager.removeUser();
|
userManager.removeUser();
|
||||||
return userManager.signoutRedirect();
|
return userManager.signoutRedirect({ id_token_hint: id_token });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function signoutRedirectCallback() {
|
export function signoutRedirectCallback() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user