Giter Site home page Giter Site logo

defineiot / keyauth Goto Github PK

View Code? Open in Web Editor NEW
27.0 5.0 5.0 4.83 MB

user account and authentication server with oauth 2.0

Go 98.86% Shell 0.93% Makefile 0.19% Dockerfile 0.02%
user-management oauth2-provider multi-tenant rbac-management keystone servicediscovery pkce

keyauth's Introduction

Keyauth

keyauth是一个分布式或者微服务场景下的鉴权中心, 遵循OAuth2.0规范, 参考openstack keystonecloud foundry uaa设计而成, 提供如下功能:

  • 支持多租户用户管理
  • 支持OAuth2.0的中心化的身份管理
  • 支持RBAC的鉴权管理
  • 支持服务目录

具体请参考设计文档iot-auth概要设计

快速开发

开发环境:

  • Golang 1.11+
  • 编辑器: 推荐使用vscod
  • 开发环境: macOS/Linux

A. 初始化数据库: sql脚本位于: cmd/ddl/schema_v1.sql

mysql -uxxxx -p < cmd/ddl/schema_v1.sql

B. 确认配置文件: 配置文件位于: cmd/etc/keyauth.conf, 提前配置好本地的数据库等相关配置

[mysql]
host = "127.0.0.1"
port = "3306"
db = "keyauth"
user = "root"
pass = "passwd"
max_open_conn = 1000
max_idle_conn = 200
max_life_time = 60

C. 初始化系统管理员信息(仅需执行一次)

➜  keyauth git:(master) ✗ make init_admin
[INIT] 开始初始化 系统需要的角色 ...
[INIT] 创建系统管理员角色成功: system_admin
[INIT] 创建租户管理员成功: domain_admin
[INIT] 创建普通成员角色成功: member
[INIT] 开始初始化 系统管理员账户 ...
[INIT] 创建系统管理员部门成功: admin_department
[INIT] 创建系统管理员默认部门成功: default_department
[INIT] 创建系统管理员成功: admin
[INIT] 绑定系统管理员角色成功
[INIT] 绑定租户管理员角色成功
[INIT] 开始初始化 系统管理员应用 ...
[INIT] 创建Web端应用应用成功: client_id -> C1ZRpSzHM6KlhCHiC4kkML66, client_secret -> xqDAZ7kvhNGmLWppQmNZZ1vsYKtH5Nix
[INIT] 创建安卓端应用应用成功: client_id -> TR4pg4Z4FGNTDUsozMtL4f8S, client_secret -> gAtl5xfAES9ezVFW2TeHuACimeTob56s
[INIT] 创建IOS端应用应用成功: client_id -> r1n8Cjvxqy3dFakuhf5haOXL, client_secret -> usxy3jeRDZUG07V8FJE67b7DbbwcIYUl
[INIT] 创建SDK端应用应用成功: client_id -> aTgFOL7Yesq0NSqfILpKQ6A0, client_secret -> 8iZZ78kEaGag5KEf7l2UjpbsiWIJS3Y0
[INIT] 系统管理员初始化完成

D. 启动服务

➜  keyauth git:(master) ✗ make run
DEBU[0000] initial global variables success
DEBU[0000] registry github.com/defineiot/keyauth service features success
INFO[0000] starting keyauth service at 127.0.0.1:8080

keyauth's People

Contributors

toliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

keyauth's Issues

Db对象和Logger对象被返回初始化

问题描述

如下实例化一个DB对象的代码中,调用GetDBConn的时候,由于sync.Once对象被重新声明,所以initDBConn函数一定会被执行。达不到initDBConn只被执行一次的目的

func (c *Config) GetDBConn() (*sql.DB, error) {
	var (
		err  error
		once sync.Once
	)

	once.Do(func() {
		err = c.initDBConn()
	})

解决建议

sync.Once对象声明为Config结构体的一个参数,命名为DbOnce,与Logger区分

实例化storage时不应该传入db

问题描述

func NewDomainStorage(db *sql.DB) domain.Storage {
	return &manager{db: db}
}

初始化storage不应该传入db, 如果初始化storage需要db,不利于解耦数据库与storage

解决建议

通过配置文件配置storage的实现,New storage的时候不需要传入参数,根据配置文件获取storage,便于storage的解耦与扩展

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.