Giter Site home page Giter Site logo

introspector's Introduction

use 'godoc cmd/github.com/codeclysm/introspector' for documentation on the github.com/codeclysm/introspector command

Package introspector

import "github.com/codeclysm/introspector"

Package introspector abstracts the process of gaining info from an authentication token.

In a perfect world you'll have to handle authentication only once, and only from a perfectly standard Oauthx solution that you can plug in every project.

Reality is different. In reality you have to handle a messy authentication system with oauth2, along with some hardcoded api keys that no one knows who put there, and on top of it all you have to introduce a brand new (but still messy) authentication system. apps.

Introspector introduces the concept of collections. It returns info from the first system that understands what you're talking about.

	j1 := introspector.JWT{
		Key: []byte("secret"),
	}

	j2 := introspector.JWT{
		Key: []byte("terces"),
	}

	collection := introspector.Collection{j1, j2}

	i, err := collection.Introspect("eyJh...lIw")
	fmt.Println(err)
	fmt.Println(i.Subject)
	fmt.Println(i.Active)
	fmt.Println(i.ExpiresAt)
	// Output:
	// <nil>
	// test
	// false
	// 1486394779

You can also test for a given permission, assuming that your system understands them:

    perm := introspector.Permission{
        Action: "delete",
        Resource: "users",
    }

    i, can, err := custom.Allowed(token, perm, "administration")

We are asking if the token has the permission of deleting users in the scope administration.

You can implement your own introspectors, as long as you satisfy the necessary interfaces.

Learn more at https://godoc.org/github.com/codeclysm/introspector

introspector's People

Contributors

matteosuppo avatar serjlee avatar

Watchers

Alps Tsui avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.