6b49aed88a
* initial commit * created httpreq struct * checked against env key * wrapped up comparing xapikey to flag input * added readme * added example and updated code with viper * added ConstantTimeCompare function * fixed spacing * updated with comments, and updated readme * updated main.go with setting env variable * fixed linter errors
34 lines
668 B
Go
34 lines
668 B
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"storj.io/storj/netstate/auth"
|
|
|
|
"github.com/spf13/pflag"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// example of how the auth package is working.
|
|
// see readme in auth/ for how to run
|
|
func main() {
|
|
|
|
pflag.String("key", "", "this is your API KEY")
|
|
viper.BindPFlag("key", pflag.Lookup("key"))
|
|
pflag.Parse()
|
|
|
|
viper.SetEnvPrefix("API")
|
|
os.Setenv("API_KEY", "12345")
|
|
viper.AutomaticEnv()
|
|
|
|
httpRequestHeaders := auth.InitializeHeaders()
|
|
xAPIKey := httpRequestHeaders.Get("X-Api-Key")
|
|
|
|
isAuthorized := auth.ValidateAPIKey(xAPIKey)
|
|
fmt.Println(isAuthorized)
|
|
}
|