Okta role manager for Casbin

Clone this repo:
  1. d8ea299 feat: fix CI: configure semantic-release for Go repository (#12) by Yang Luo · 6 weeks ago master v1.0.0
  2. f9e1c68 feat: upgrade dependencies and migrate CI to GitHub Actions by Yang Luo · 6 weeks ago
  3. 3176e17 feat: use Okta official Go sdk (#5) by Aayush Sarva · 3 years, 4 months ago
  4. 621bc2e feat: add missing methods from the latest RoleManager interface (#2) by Aayush Sarva · 3 years, 4 months ago
  5. 24ddb99 Fix import format. by Yang Luo · 7 years ago

Okta Role Manager

Go Report Card CI Coverage Status Godoc Release Discord Sourcegraph

Okta Role Manager is the Okta role manager for Casbin. With this library, Casbin can load role hierarchy (user-role mapping) from Okta or save role hierarchy to it (NOT Implemented).

Installation

go get github.com/casbin/okta-role-manager

Simple Example

package main

import (
	"github.com/casbin/casbin/v2"
	oktarolemanager "github.com/casbin/okta-role-manager"
)

func main() {
	// This role manager does not rely on Casbin policy. So we should not
	// specify grouping policy ("g" policy rules) in the .csv file.
	e, _ := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")

	// Use our role manager.
	// orgName is your organization name.
	// apiToken is the token you created in the Admin portal.
	// For example, if your domain name is like: dev-123456.oktapreview.com,
	// then your orgName is dev-123456, isProductionOrPreview is false.
	// If your domain name is like: company_name.okta.com, then your orgName
	// is company_name, isProductionOrPreview is true.
	rm := oktarolemanager.NewRoleManager("dev-000000", "your_api_token", false)
	e.SetRoleManager(rm)

	// If our role manager relies on Casbin policy (like reading "g"
	// policy rules), then we have to set the role manager before loading
	// policy.
	//
	// Otherwise, we can set the role manager at any time, because role
	// manager has nothing to do with the adapter.
	e.LoadPolicy()
	
	// Check the permission.
	// Casbin's subject (user) name uses the Okta user's login field (aka Email address).
	// Casbin's role name uses the Okta group's name field (like "Admin", "Everyone").
	e.Enforce("alice@test.com", "data1", "read")
}

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.