<commit_before>// Package ghoauth provides acces_token creation for your github application
//
// Two steps:
//	1. redirect user to github auth page
//	2. create an access_token
//
// Example:
//	package main
//
//	import (
//		"github.com/vvo/go-ghoauth"
//		"net/http"
//	)
//
//	var ghflow = ghoauth.New(&ghoauth.Config{
//		ClientId:     "82c041166d565cf2f149",
//		ClientSecret: "6458b989c06d8106f468fd47106d8654e3887d5b",
//		RedirectUri:  "http://localhost:8080/callback",
//		Scope:        "user:public",
//	})
//
//	func main() {
//		// step 1: redirect users to the right github oauth page
//		// https://developer.github.com/v3/oauth/#redirect-users-to-request-github-access
//		http.HandleFunc("/login", ghflow.Login)
//		http.HandleFunc("/callback", callback)
//
//		http.HandleFunc("/", root)
//		panic(http.ListenAndServe(":8080", nil))
//	}
//
//	func callback(w http.ResponseWriter, r *http.Request) {
//		// step 2: github calls you using redirect_uri
//		// we generate a token using github oauth access_token POST url
//		// callback does not responds to client for you, it only generates a token
//		// https://developer.github.com/v3/oauth/#github-redirects-back-to-your-site
//		token, err := ghflow.Callback(r)
//
//		if err != nil {
//			w.Write([]byte("UhOh!"))
//		}
//
//		// token is now available and usable
//		w.Write([]byte("Here's your access_token budy: " + token))
//	}
//
//	func root(w http.ResponseWriter, r *http.Request) {
//		w.Write([]byte("<a href=/login>login</a>"))
//	}
//
package ghoauth

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/satori/go.uuid"
	"net/http"
	"net/url"
	"path"
)

const (
	defaultBaseUrl = "https://github.com"
)

// See https://developer.github.com/v3/oauth/#web-application-flow
// to understand how to fill the properties
type Config struct {
	ClientId     string
	ClientSecret string

	RedirectUri string

	// Comma separated list of scopes https://developer.github.com/v3/oauth/#scopes
	Scope string

	// Defaults to defaultBaseUrl
	BaseUrl string
}

type oauthFlow struct {
	*Config
}

// refers to https://developer.github.com/v3/oauth/#github-redirects-back-to-your-site
// "If the states don’t match, the request has been created
//  by a third party and the process should be aborted."
var ErrStateNotFound = errors.New("Provided `state` was not found")<commit_msg>chore(doc): fix comment<commit_after>// Package ghoauth provides acces_token creation for your github application
//
// Two steps:
//	1. redirect user to github auth page
//	2. create an access_token
//
// Example:
//	package main
//
//	import (
//		"github.com/vvo/go-ghoauth"
//		"net/http"
//	)
//
//	var ghflow = ghoauth.New(&ghoauth.Config{
//		ClientId:     "82c041166d565cf2f149",
//		ClientSecret: "6458b989c06d8106f468fd47106d8654e3887d5b",
//		RedirectUri:  "http://localhost:8080/callback",
//		Scope:        "user:public",
//	})
//
//	func main() {
//		// step 1: redirect users to the right github oauth page
//		// https://developer.github.com/v3/oauth/#redirect-users-to-request-github-access
//		http.HandleFunc("/login", ghflow.Login)
//		http.HandleFunc("/callback", callback)
//
//		http.HandleFunc("/", root)
//		panic(http.ListenAndServe(":8080", nil))
//	}
//
//	func callback(w http.ResponseWriter, r *http.Request) {
//		// step 2: github calls you using redirect_uri
//		// we generate a token using github oauth access_token POST url
//		// callback does not responds to client for you, it only generates a token
//		// https://developer.github.com/v3/oauth/#github-redirects-back-to-your-site
//		token, err := ghflow.Callback(r)
//
//		if err != nil {
//			w.Write([]byte("UhOh!"))
//		}
//
//		// token is now available and usable
//		w.Write([]byte("Here's your access_token budy: " + token))
//	}
//
//	func root(w http.ResponseWriter, r *http.Request) {
//		w.Write([]byte("<a href=/login>login</a>"))
//	}
//
package ghoauth

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/satori/go.uuid"
	"net/http"
	"net/url"
	"path"
)

const (
	defaultBaseUrl = "https://github.com"
)

// See https://developer.github.com/v3/oauth/#web-application-flow
// to understand how to fill the properties
type Config struct {
	ClientId     string
	ClientSecret string

	RedirectUri string

	// Comma separated list of scopes https://developer.github.com/v3/oauth/#scopes
	Scope string

	// Defaults to defaultBaseUrl
	BaseUrl string
}

type oauthFlow struct {
	*Config
}

// refers to https://developer.github.com/v3/oauth/#github-redirects-back-to-your-site
// "If the states don’t match, the request has been created
// by a third party and the process should be aborted."
var ErrStateNotFound = errors.New("Provided `state` was not found")
{'fraction_non_alphanumeric': 0.16599533601865593, 'fraction_numerical': 0.026287894848420607, 'mean_word_length': 3.095486111111111, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6089548', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1683, 'n_words': 401}