Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Casbin-dashboard is the official web UI (admin portal) for Casbin models and pol

## Demo

https://dashboard.casbin.org/
https://dashboard.casbin.com

## Architecture

Expand All @@ -28,17 +28,23 @@ go get github.com/casbin/casbin-dashboard

Casbin-dashboard will store its metadata in a MySQL database named: `casbin_metadata`, will create it if not existed. The DB connection string can be specified at: https://github.com/casbin/casbin-dashboard/blob/master/conf/app.conf

- Setup casbin-dashboard to enable some third-party login platform

Casbin-forum provide a way to sign up using Github account, so you may have to get your own `GithubAuthClientID`, `GithubAuthClientSecret` first.

You could get them by clicking on this url: https://github.com/settings/developers , You should set `Homepage URL` to fit your own domain address, for local testing, set`http://localhost:3000`. And set the Authorization callback URL, the same domain address as `Homepage URL`, for local testing, set`http://localhost:3000`.

- Modified config files:

Change your own `GithubAuthClientID`, `GithubAuthClientSecret` in conf/app.conf, web/src/conf.js.

```ini
dataSourceName = root:123@tcp(localhost:3306)/
```

Casbin-dashboard uses XORM to connect to DB, so all DBs supported by XORM can also be used.

- Modified config files:

Change your `GithubAuthClientID`, `GithubAuthClientSecret` in conf/app.conf, web/src/conf.js.

- Run backend (in port 8000):
- Run backend (in port 8800):

```
go run main.go
Expand Down
2 changes: 1 addition & 1 deletion conf/app.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appname = casbin-dashboard
httpport = 8000
httpport = 8800
runmode = dev
SessionOn = true
copyrequestbody = true
Expand Down
47 changes: 32 additions & 15 deletions controllers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,41 +82,58 @@ func (c *ApiController) AuthGithub() {
var tempUserEmail []userEmailFromGithub
var tempUserAccount userInfoFromGithub
wg.Add(2)
client := &http.Client{}
go func() {
defer wg.Done()
response, err := http.Get("https://api.github.com/user/emails?access_token=" + token.AccessToken)
req, err := http.NewRequest("GET", "https://api.github.com/user/emails", nil)
if err != nil {
res.IsAuthenticated = false
beego.Error(err)
beego.Error("Unexpected error while generate request", err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
err = json.Unmarshal(contents, &tempUserEmail)
req.Header.Add("access", "application/vnd.github.v3+json")
req.Header.Add("Authorization", "token "+token.AccessToken)
response, err := client.Do(req)
if err != nil {
res.IsAuthenticated = false
beego.Error(err)
}
for _, v := range tempUserEmail {
if v.Primary == true {
res.Email = v.Email
break
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
err = json.Unmarshal(contents, &tempUserEmail)
if err != nil {
res.IsAuthenticated = false
beego.Error(err)
}
for _, v := range tempUserEmail {
if v.Primary == true {
res.Email = v.Email
break
}
}
}
}
}()
go func() {
defer wg.Done()
response2, err := http.Get("https://api.github.com/user?access_token=" + token.AccessToken)
req, err := http.NewRequest("GET", "https://api.github.com/user", nil)
if err != nil {
res.IsAuthenticated = false
beego.Error("Unexpected error while processing get account", err)
beego.Error("Unexpected error while generate request", err)
} else {
defer response2.Body.Close()
contents2, err := ioutil.ReadAll(response2.Body)
err = json.Unmarshal(contents2, &tempUserAccount)
req.Header.Add("access", "application/vnd.github.v3+json")
req.Header.Add("Authorization", "token "+token.AccessToken)
response2, err := client.Do(req)
if err != nil {
res.IsAuthenticated = false
beego.Error("Unexpected error while processing get account", err)
} else {
defer response2.Body.Close()
contents2, err := ioutil.ReadAll(response2.Body)
err = json.Unmarshal(contents2, &tempUserAccount)
if err != nil {
res.IsAuthenticated = false
beego.Error("Unexpected error while processing get account", err)
}
}
}
}()
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ require (
github.com/casbin/xorm-adapter/v2 v2.0.1
github.com/go-sql-driver/mysql v1.5.0
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
xorm.io/xorm v0.8.1
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
Expand Down Expand Up @@ -144,11 +145,13 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -170,6 +173,7 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.0 h1:Tfd7cKwKbFRsI8RMAD3oqqw7JPFRrvFlOsfbgVkjOOw=
google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
Expand Down
6 changes: 2 additions & 4 deletions web/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

module.exports = {
extends: ["eslint:recommended",
"plugin:react/recommended"],
extends: ['eslint:recommended', 'plugin:react/recommended'],
rules: {
'react/jsx-filename-extension': 'off',
},
};
};
3 changes: 0 additions & 3 deletions web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ yarn-error.log*

.idea/
*.iml

package-lock.json
yarn.lock
11 changes: 0 additions & 11 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,5 @@
"husky": "^4.2.3",
"lint-staged": "^10.0.8",
"prettier": "^1.19.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"./src/*.{js,jsx,ts,tsx}": [
"npx prettier --write",
"eslint src/*.js --fix-dry-run"
]
}
}
Loading