Skip to content

Instantly share code, notes, and snippets.

View cyantarek's full-sized avatar
🏠
Working from home

Cyan Tarek cyantarek

🏠
Working from home
View GitHub Profile
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
package main
import (
"fmt"
"io/ioutil"
"log"
)
func main() {
f, err := ioutil.ReadFile("download.png")
[10001001 1010000 1001110 1000111 1101 1010 11010 1010 0 0 0 1101 1001001 1001000 1000100 1010010 0 0 0 11000000 0 0 1 110 1000 11 0 0 0 100 11000100 1101010 101000 0 0 1 10111 1010000 1001100 1010100 1000101 1101001 11010111 11100010 11111111 11111111 11111111 0 0 0 11110110 11010010 10100010 1101100 11011110 11101001 1101010 11011010 11100101 1101101 11011111 11101010 11011010 11011010 11011010 11111111 11011010 10101000 1010101 10101110 10110111 11111100 11010111 10100110 11111000 11111000 11111000 11111011 11111011 11111011 11101110 11101110 11101110 11100110 11100110 11100110 11000000 11000000 11000000 1100110 11010000 11011011 11011110 11011110 11011110 11010000 11010000 11010000 1100111 11010010 11011101 1011110 11000001 11001011 11110011 11110011 11110011 1010111 10110010 10111011 10111010 10111010 10111010 1011011 10111011 11000100 10100011 10100011 10100011 1100010 11001001 11010011 111101 1111110 10000101 10011000 10011000 10011000 11001010 11001010 11001010 10110000 10110000 10110000 1000111 10010
// genKey generates 256 random bytes
func genKey() string {
token := make([]byte, 8)
// error checking ommiting for the
// sake of this tutorial
// but you SHOULD not avoid it in production
_, _ = rand.Read(token)
return hex.EncodeToString(token)
}
http.HandleFunc("/credentials", func(w http.ResponseWriter, r *http.Request) {
domain := r.Header.Get("DOMAIN")
if domain == "" {
http.Error(w, "domain missing", 500)
return
}
clientId := genKey()
clientSecret := genKey()
err := clientStore.Set(clientId, &models.Client{
package main
import (
"log"
"net/http"
)
func main() {
http.HandleFunc("/protected", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, I'm protected"))
package main
import (
"fmt"
"github.com/gorilla/websocket"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"net/http"
"os"
package main
import (
"log"
"net/http"
)
func main() {
http.HandleFunc("/protected", validateToken(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, I'm protected"))
package main
import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"gopkg.in/oauth2.v3/models"
"log"
"net/http"
"time"
http.HandleFunc("/protected", validateToken(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, I'm protected"))
}, srv))