Skip to content

Instantly share code, notes, and snippets.

@bragnikita
bragnikita / tokens.md
Created October 8, 2019 01:18 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Основы:

Аутентификация(authentication, от греч. αὐθεντικός [authentikos] – реальный, подлинный; от αὐθέντης [authentes] – автор) - это процесс проверки учётных данных пользователя (логин/пароль). Проверка подлинности пользователя путём сравнения введённого им логина/пароля с данными сохранёнными в базе данных.

Авторизация(authorization — разрешение, уполномочивание) - это проверка прав пользователя на доступ к определенным ресурсам.

Например после аутентификации юзер sasha получает право обращатся и получать от ресурса "super.com/vip" некие данные. Во время обращения юзера sasha к ресурсу vip система авторизации проверит имеет ли право юзер обращатся к этому ресурсу (проще говоря переходить по неким разрешенным ссылкам)

@bragnikita
bragnikita / rspec_model_testing_template.rb
Created March 11, 2018 09:57 — forked from PWSdelta/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@bragnikita
bragnikita / CURL-cheatsheet.md
Created February 5, 2018 01:41 — forked from Kartones/CURL-cheatsheet.md
CURL Cheatsheet
  • XML GET
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET "http://hostname/resource"
  • JSON GET
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET "http://hostname/resource"
  • JSON PUT
@bragnikita
bragnikita / httpserver.rb
Created January 12, 2017 05:48
Simple Ruby http server
require 'webrick'
class Echo < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
serve request, response
end
def do_POST(request, response)
serve request, response
end
def serve(request, response)
@bragnikita
bragnikita / regex_hint.java
Created January 11, 2017 08:44
Java regular expressions API demo
public class RegexpHint {
public static void main(String[] args) {
Map<String, String> map = new HashMap<>();
map.put("title", "Oriko"); map.put("volume", "01"); map.put("chapter", "4");
String input = "Title: $title; volume: $volume; chapter $chapter; ready";
String regex = "\\$(\\w+)";
Matcher m = Pattern.compile(regex).matcher(input);
m.region(7,13);
@bragnikita
bragnikita / regex_methods.js
Last active January 10, 2017 08:43
Javascript Regex usage
//
var res = regex.test(str);
// res == true; true или false (есть хоть одно совпадение или нет)
//exec
//для не-g - шаблона - полный аналог str.match
//для глобального - ищет все совпадения и все группы
/*
При каждом вызове над одним и тем же объектом Regex
возвращает объект match (со знач. скобок) или null, если совпадений больше нет,
@bragnikita
bragnikita / ssh.md
Last active December 7, 2016 06:46

#X509 Certificate and keys formats and encodings Encodings (also used as extensions)

.DER = The DER extension is used for binary DER encoded certificates. These files may also bear the CER or the CRT extension. Proper English usage would be “I have a DER encoded certificate” not “I have a DER certificate”.

.PEM = The PEM extension is used for different types of X.509v3 files which contain ASCII (Base64) armored data prefixed with a “—– BEGIN …” line.

##Common Extensions

.CRT = The CRT extension is used for certificates. The certificates may be encoded as binary DER or as ASCII PEM. The CER and CRT extensions are nearly synonymous. Most common among *nix systems

@bragnikita
bragnikita / gist:730c8fad55178a578f9e68d7b2cb1e09
Created December 6, 2016 09:48 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt