Beispiel #1
0
func NewShortener(issuer string, key []byte) (s *Shortener, err error) {
	s = &Shortener{}
	token := jwt.NewToken(issuer, urlshortener.UrlshortenerScope, key)
	if s.transport, err = jwt.NewTransport(token); err != nil {
		return
	}
	s.svc, err = urlshortener.New(s.transport.Client())
	return
}
Beispiel #2
0
func prepareServiceClient(data *oauthConfig, keyBytes []byte) (
	*http.Client, error) {
	// Craft the ClaimSet and JWT token.
	token := jwt.NewToken(data.Web.Client_Email, oauthScope, keyBytes)
	token.ClaimSet.Aud = data.Web.Token_Uri

	transport, err := jwt.NewTransport(token)
	if err != nil {
		log.Fatal("Assertion error:", err)
	}

	return transport.Client(), nil
}
Beispiel #3
0
func NewGCSStorage(gcsClientEmail, gcsTokenURI string, gcsPemBytes []byte) (Storage, error) {
	t := jwt.NewToken(gcsClientEmail, storage.DevstorageFull_controlScope, gcsPemBytes)
	t.ClaimSet.Aud = gcsTokenURI
	transport, err := jwt.NewTransport(t)
	if err != nil {
		return nil, err
	}
	client := transport.Client()
	gcsService, err := storage.New(client)
	if err != nil {
		return nil, err
	}
	return &GoogleCloudStorage{gcsService}, nil
}
Beispiel #4
0
func main() {

	token := jwt.NewToken(Email, Scope, []byte(PEM))
	transport, err := jwt.NewTransport(token)
	if err != nil {
		log.Fatal(err)
	}

	client := transport.Client()
	bq, err := bigquery.New(client)
	if err != nil {
		log.Fatal(err)
	}

	rows := make([]*bigquery.TableDataInsertAllRequestRows, 0)

	row := &bigquery.TableDataInsertAllRequestRows{
		Json: make(map[string]bigquery.JsonValue, 0),
	}
	row.Json["url"] = "https://github.com"
	row.Json["source"] = "example"
	row.Json["t"] = time.Now().Unix()
	row.Json["http_status"] = 200

	rows = append(rows, row)

	req := &bigquery.TableDataInsertAllRequest{
		Rows: rows,
	}

	call := bq.Tabledata.InsertAll(App, Dataset, Table, req)
	resp, err := call.Do()
	if err != nil {
		log.Fatal(err)
	}

	buf, _ := json.Marshal(resp)
	log.Print(string(buf))
}