Skip to content

Instantly share code, notes, and snippets.

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
@nicoclau
nicoclau / Dockerfile
Created June 25, 2022 20:27
Dockerfile
# pull official base image
FROM node:16.9.1-alpine3.14
# set working directory
WORKDIR /reactapp
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install --silent
@nicoclau
nicoclau / .dockerignore
Created June 25, 2022 20:08
.dockerignore
# Items that don't need to be in a Docker image.
# Anything not used by the build system should go here.
Dockerfile
.dockerignore
.gitignore
README.md
# Artifacts that will be built during image creation.
# This should contain all files created during `npm run build`.
build
@nicoclau
nicoclau / Program.cs
Last active June 23, 2022 09:15
Program
using Microsoft.IdentityModel.Tokens;
using System;
using System.Security.Cryptography;
namespace Cryptography
{
internal class Program
{
static void Main(string[] args)
{
@nicoclau
nicoclau / JWSWithRS256.cs
Last active June 23, 2022 09:12
JWSWithRS256
using Microsoft.IdentityModel.Tokens;
using System;
using System.Security.Cryptography;
namespace Cryptography
{
public static class JwsWithRS256
{
/// <summary>
/// To validate the JWS signature
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@nicoclau
nicoclau / Startup.cs
Last active June 16, 2022 13:42
Startup.cs
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
@nicoclau
nicoclau / App.tsx
Last active June 16, 2022 12:38
App
import React from "react";
import logo from "./logo.svg";
import "./App.css";
import KeyCloakService from "./security/KeyCloakService";
import HttpService from "./services/HttpServices";
function logout() {
KeyCloakService.CallLogout();
}
@nicoclau
nicoclau / Index.tsx
Created June 16, 2022 09:41
Index.tsx
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import KeyCloakService from "./security/KeyCloakService";
import HttpService from "./services/HttpServices";
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
@nicoclau
nicoclau / KeyCloakService.ts
Last active October 19, 2022 14:34
KeyCloakService
import Keycloak from "keycloak-js";
const keycloakInstance = new Keycloak();
/**
* Initializes Keycloak instance and calls the provided callback function if successfully authenticated.
*
* @param onAuthenticatedCallback
*/
const Login = (onAuthenticatedCallback: Function) => {