storj/examples/auth/main.go
Maximillian von Briesen ff92caa5b0
rename netstate to pointerdb (#127)
* rename netstate to pointerdb
2018-07-06 15:43:53 -04:00

34 lines
669 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"fmt"
"os"
"storj.io/storj/pointerdb/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)
}