Ejemplo n.º 1
0
func main() {

	// create an auth client
	a := auth.NewAuth(
		auth.Id("asim"),
		auth.Secret("foobar"),
	)

	// retreive a token
	t, err := a.Token()
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("Retreived Token %+v\n", t)

	ctx := a.NewContext(context.TODO(), t)

	// introspect a token from context
	t, err = a.Introspect(ctx)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("Introspected Token %+v\n", t)

	req := client.NewRequest("go.micro.example", "Example.Method", "request")

	// check if context/request is authorized
	t, err = a.Authorized(ctx, req)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("Authorized Token %+v\n", t)
}
Ejemplo n.º 2
0
func NewAuth(opts ...auth.Option) auth.Auth {
	return auth.NewAuth(opts...)
}