Skip to content

Instantly share code, notes, and snippets.

View sadrakgunadi's full-sized avatar
🎯
Focusing

Sadrak Gunadi sadrakgunadi

🎯
Focusing
View GitHub Profile
@sadrakgunadi
sadrakgunadi / Web API CORS Preflight issues
Last active March 30, 2019 15:47
Web API CORS Preflight issues
Web Config
-----------
<system.webServer>
<httpProtocol>
<!--<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>-->
@sadrakgunadi
sadrakgunadi / Token Validation Parameter
Created February 11, 2019 09:50
Token Validation Parameter
TokenValidationParameters tvp = new TokenValidationParameters() {
ValidateActor = false,
// check the profile ID
ValidateAudience = true,
// check the client ID
ValidAudience = CLIENT_ID,
ValidateIssuer = true,
// check token came from Google
ValidIssuers = new List < string > {
@sadrakgunadi
sadrakgunadi / Keycloak-REST API (Delete existing user)
Last active February 7, 2019 09:43
Keycloak-REST API (Delete existing user)
URL :
http://localhost:8080/auth/admin/realms/master/users/{user_id}
Method : DELETE
HEADER :
Bearer token
@sadrakgunadi
sadrakgunadi / Keycloak-REST API (Update existing user)
Created February 7, 2019 04:56
Keycloak-REST API (Update existing user)
URL :
http://localhost:8080/auth/admin/realms/master/users/{user_id}
Method : PUT
Header :
Bearer token
Body :
{
@sadrakgunadi
sadrakgunadi / Keycloak-REST API (Add new user)
Last active February 25, 2019 06:39
Keycloak-REST API (Add new user)
URL :
http://localhost:8080/auth/admin/realms/master/users
Method : POST
Header :
Bearer token
Body :
{
@sadrakgunadi
sadrakgunadi / SG.UnixTime Converter.md
Last active February 5, 2019 01:42
Convert Date Time to Unix Time Stamp and Vice Versa

SG.UnixTime

Unix Time Converter

Convert Date Time to Unix Timestamp and Vice Versa (seconds or milliseconds format)

Import Reference

using SG.UnixTime;

Convert DateTime to Unix Timestamp

example 1 :

@sadrakgunadi
sadrakgunadi / RSAKeyPairGeneratorWithBouncyCastle.md
Last active March 25, 2023 20:12
Generate RSA Key Pair with BouncyCastle

Generate RSA Key Pair with BouncyCastle

Source : BouncyCastle

Code

RsaKeyPairGenerator g = new RsaKeyPairGenerator();
@sadrakgunadi
sadrakgunadi / RSAWithBouncyCastle.md
Last active February 28, 2021 02:24
RSA Key Exchange with BouncyCastle

RSA Key Exchange with BouncyCastle

Source : BouncyCastle

Code

class Program {

	private static RSAParameters rsaPubParams;
@sadrakgunadi
sadrakgunadi / VerifySignatureJWT.md
Last active January 25, 2019 15:35
Verify Signature JWT

Verify Signature JWT

Includes types that provide support for creating, serializing and validating JSON Web Tokens.

Code

string tokenStr = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJwZG0yeG9TbWowOXY4R2xWSjlBRm9iNkw3Ylk5aVVXMVdmanhlMWFIeTdrIn0.eyJqdGkiOiI0NzYwYWRmNC04NjNjLTRmMTQtYTYxMC1iNWNkMWMwOTY0YTgiLCJleHAiOjE1NDgyODcxNDAsIm5iZiI6MCwiaWF0IjoxNTQ4Mjg2NTQwLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvbWFzdGVyIiwic3ViIjoiZWZiOTJhY2YtMmUzZS00YWUwLTg0NzUtOTA0NjE5YTVmOTkzIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibXlhcHAiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiI5MTZiODkwMy1jYTUxLTQzZWYtYjM1Ni0wOTkxZGM1ZjE3MzUiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC8iXSwic2NvcGUiOiJlbWFpbCBwcm9maWxlIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJuYW1lIjoiU2FkcmFrIEd1bmFkaSIsInByZWZlcnJlZF91c2VybmFtZSI6InNhZHJhayIsImdpdmVuX25hbWUiOiJTYWRyYWsiLCJmYW1pbHlfbmFtZSI6Ikd1bmFkaSIsImVtYWlsIjoi
@sadrakgunadi
sadrakgunadi / OTP.md
Created January 25, 2019 14:51
TOTP & HOTP .Net Framework

Otp.NET ( TOTP & HOTP)

An implementation of TOTP and HOTP which are commonly used for multi factor authentication by using a shared key between the client and the server to generate and verify one time use codes.

Code

long _counter = 0;
string isRepeat = "N";