<commit_before>package oauth

import (
	"strings"
	"encoding/base64"
	"os"
	"json"
)

type SignedRequest struct {
	Algorithm  string
	Expires    float64
	IssuedAt   float64
	OAuthToken string
	UserID     string
}

func ParseSignedRequest(input string) (sr SignedRequest, err os.Error) {
	d := strings.Split(input, ".", -1)
	//signature := DecodeBase64URL(d[0])
	data := DecodeBase64URL(d[1])

	var values interface{}
	if err = json.Unmarshal([]byte(data), &values); err != nil {
		return
	}
	val := values.(map[string]interface{})
	sr.Algorithm = val["algorithm"].(string)
	sr.Expires = val["expires"].(float64)
	sr.IssuedAt = val["issued_at"].(float64)
	sr.OAuthToken = val["oauth_token"].(string)
	sr.UserID = val["user_id"].(string)
	return
	// TODO: Check SignedRequest with signature
}

func DecodeBase64URL(s string) string {
	s += "=" // Facebook fix, facebook sends corrupted base64_url
	dbuf := make([]byte, base64.URLEncoding.DecodedLen(len(s)))
	_, err := base64.URLEncoding.Decode(dbuf, []byte(s))
	if err != nil {
		println(err.String())
	}
	return string(dbuf)
}
<commit_msg>Temp bypass an illegal char at the end of the encoded SignedRequest data part.<commit_after>package oauth

import (
	"strings"
	"encoding/base64"
	"os"
	"json"
)

type SignedRequest struct {
	Algorithm  string
	Expires    float64
	IssuedAt   float64
	OAuthToken string
	UserID     string
}

func ParseSignedRequest(input string) (sr SignedRequest, err os.Error) {
	d := strings.Split(input, ".", -1)
	//signature := DecodeBase64URL(d[0])
	data, err := DecodeBase64URL(d[1])
	if err != nil {
		return
	}
	data = data[:len(data)-1] // TEMP: Bypass an illegal char at the end
	var values interface{}
	if err = json.Unmarshal([]byte(data), &values); err != nil {
		return sr, os.NewError("Error: ParseSignedRequest: json.Unmarshal: " + err.String() + " in " + data)
	}
	val := values.(map[string]interface{})
	sr.Algorithm = val["algorithm"].(string)
	sr.Expires = val["expires"].(float64)
	sr.IssuedAt = val["issued_at"].(float64)
	sr.OAuthToken = val["oauth_token"].(string)
	sr.UserID = val["user_id"].(string)
	return
	// TODO: Check SignedRequest with signature
}

func DecodeBase64URL(s string) (string, os.Error) {
	s += "=" // Facebook fix, facebook sends corrupted base64_url
	dbuf := make([]byte, base64.URLEncoding.DecodedLen(len(s)))
	_, err := base64.URLEncoding.Decode(dbuf, []byte(s))
	if err != nil {
		return "", err
	}
	return string(dbuf), err
}

{'fraction_non_alphanumeric': 0.1546938775510204, 'fraction_numerical': 0.020816326530612245, 'mean_word_length': 4.470982142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5972003', 'n_tokens_mistral': 926, 'n_tokens_neox': 885, 'n_words': 208}