Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
e5fc4332
Commit
e5fc4332
authored
Sep 28, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(oauth): refactoring PR #6077
parent
5ccdbf01
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
48 deletions
+26
-48
pkg/api/login.go
+6
-5
pkg/setting/setting_oauth.go
+1
-2
pkg/social/social.go
+9
-24
public/app/core/controllers/login_ctrl.js
+5
-12
public/app/partials/login.html
+5
-5
No files found.
pkg/api/login.go
View file @
e5fc4332
...
...
@@ -25,11 +25,12 @@ func LoginView(c *middleware.Context) {
return
}
viewData
.
Settings
[
"googleAuthEnabled"
]
=
setting
.
OAuthService
.
Google
viewData
.
Settings
[
"githubAuthEnabled"
]
=
setting
.
OAuthService
.
GitHub
viewData
.
Settings
[
"grafanaNetAuthEnabled"
]
=
setting
.
OAuthService
.
GrafanaNet
viewData
.
Settings
[
"genericOAuthEnabled"
]
=
setting
.
OAuthService
.
Generic
viewData
.
Settings
[
"oauthProviderName"
]
=
setting
.
OAuthService
.
OAuthProviderName
enabledOAuths
:=
make
(
map
[
string
]
interface
{})
for
key
,
oauth
:=
range
setting
.
OAuthService
.
OAuthInfos
{
enabledOAuths
[
key
]
=
map
[
string
]
string
{
"name"
:
oauth
.
Name
}
}
viewData
.
Settings
[
"oauth"
]
=
enabledOAuths
viewData
.
Settings
[
"disableUserSignUp"
]
=
!
setting
.
AllowUserSignUp
viewData
.
Settings
[
"loginHint"
]
=
setting
.
LoginHint
viewData
.
Settings
[
"allowUserPassLogin"
]
=
setting
.
AllowUserPassLogin
...
...
pkg/setting/setting_oauth.go
View file @
e5fc4332
...
...
@@ -8,12 +8,11 @@ type OAuthInfo struct {
AllowedDomains
[]
string
ApiUrl
string
AllowSignup
bool
Name
string
}
type
OAuther
struct
{
GitHub
,
Google
,
Twitter
,
Generic
,
GrafanaNet
bool
OAuthInfos
map
[
string
]
*
OAuthInfo
OAuthProviderName
string
}
var
OAuthService
*
OAuther
pkg/social/social.go
View file @
e5fc4332
...
...
@@ -51,6 +51,7 @@ func NewOAuthService() {
Enabled
:
sec
.
Key
(
"enabled"
)
.
MustBool
(),
AllowedDomains
:
sec
.
Key
(
"allowed_domains"
)
.
Strings
(
" "
),
AllowSignup
:
sec
.
Key
(
"allow_sign_up"
)
.
MustBool
(),
Name
:
sec
.
Key
(
"name"
)
.
MustString
(
name
),
}
if
!
info
.
Enabled
{
...
...
@@ -71,22 +72,18 @@ func NewOAuthService() {
// GitHub.
if
name
==
"github"
{
setting
.
OAuthService
.
GitHub
=
true
teamIds
:=
sec
.
Key
(
"team_ids"
)
.
Ints
(
","
)
allowedOrganizations
:=
sec
.
Key
(
"allowed_organizations"
)
.
Strings
(
" "
)
SocialMap
[
"github"
]
=
&
SocialGithub
{
Config
:
&
config
,
allowedDomains
:
info
.
AllowedDomains
,
apiUrl
:
info
.
ApiUrl
,
allowSignup
:
info
.
AllowSignup
,
teamIds
:
teamIds
,
allowedOrganizations
:
allowedOrganizations
,
teamIds
:
sec
.
Key
(
"team_ids"
)
.
Ints
(
","
)
,
allowedOrganizations
:
sec
.
Key
(
"allowed_organizations"
)
.
Strings
(
" "
)
,
}
}
// Google.
if
name
==
"google"
{
setting
.
OAuthService
.
Google
=
true
SocialMap
[
"google"
]
=
&
SocialGoogle
{
Config
:
&
config
,
allowedDomains
:
info
.
AllowedDomains
,
apiUrl
:
info
.
ApiUrl
,
...
...
@@ -96,35 +93,23 @@ func NewOAuthService() {
// Generic - Uses the same scheme as Github.
if
name
==
"generic_oauth"
{
setting
.
OAuthService
.
Generic
=
true
setting
.
OAuthService
.
OAuthProviderName
=
sec
.
Key
(
"oauth_provider_name"
)
.
String
()
teamIds
:=
sec
.
Key
(
"team_ids"
)
.
Ints
(
","
)
allowedOrganizations
:=
sec
.
Key
(
"allowed_organizations"
)
.
Strings
(
" "
)
SocialMap
[
"generic_oauth"
]
=
&
GenericOAuth
{
Config
:
&
config
,
allowedDomains
:
info
.
AllowedDomains
,
apiUrl
:
info
.
ApiUrl
,
allowSignup
:
info
.
AllowSignup
,
teamIds
:
teamIds
,
allowedOrganizations
:
allowedOrganizations
,
teamIds
:
sec
.
Key
(
"team_ids"
)
.
Ints
(
","
)
,
allowedOrganizations
:
sec
.
Key
(
"allowed_organizations"
)
.
Strings
(
" "
)
,
}
}
if
name
==
"grafananet"
{
setting
.
OAuthService
.
GrafanaNet
=
true
allowedOrganizations
:=
sec
.
Key
(
"allowed_organizations"
)
.
Strings
(
" "
)
url
:=
sec
.
Key
(
"url"
)
.
String
()
if
url
==
""
{
url
=
"https://grafana.net"
}
config
:=
oauth2
.
Config
{
ClientID
:
info
.
ClientId
,
ClientSecret
:
info
.
ClientSecret
,
Endpoint
:
oauth2
.
Endpoint
{
AuthURL
:
u
rl
+
"/oauth2/authorize"
,
TokenURL
:
u
rl
+
"/api/oauth2/token"
,
AuthURL
:
setting
.
GrafanaNetU
rl
+
"/oauth2/authorize"
,
TokenURL
:
setting
.
GrafanaNetU
rl
+
"/api/oauth2/token"
,
},
RedirectURL
:
strings
.
TrimSuffix
(
setting
.
AppUrl
,
"/"
)
+
SocialBaseUrl
+
name
,
Scopes
:
info
.
Scopes
,
...
...
@@ -132,9 +117,9 @@ func NewOAuthService() {
SocialMap
[
"grafananet"
]
=
&
SocialGrafanaNet
{
Config
:
&
config
,
url
:
u
rl
,
url
:
setting
.
GrafanaNetU
rl
,
allowSignup
:
info
.
AllowSignup
,
allowedOrganizations
:
allowedOrganizations
,
allowedOrganizations
:
sec
.
Key
(
"allowed_organizations"
)
.
Strings
(
" "
)
,
}
}
}
...
...
public/app/core/controllers/login_ctrl.js
View file @
e5fc4332
define
([
'angular'
,
'lodash'
,
'../core_module'
,
'app/core/config'
,
],
function
(
angular
,
coreModule
,
config
)
{
function
(
angular
,
_
,
coreModule
,
config
)
{
'use strict'
;
var
failCodes
=
{
...
...
@@ -21,18 +22,10 @@ function (angular, coreModule, config) {
contextSrv
.
sidemenu
=
false
;
$scope
.
googleAuthEnabled
=
config
.
googleAuthEnabled
;
$scope
.
githubAuthEnabled
=
config
.
githubAuthEnabled
;
$scope
.
grafanaNetAuthEnabled
=
config
.
grafanaNetAuthEnabled
;
$scope
.
oauthEnabled
=
(
config
.
githubAuthEnabled
||
config
.
googleAuthEnabled
||
config
.
grafanaNetAuthEnabled
||
config
.
genericOAuthEnabled
);
$scope
.
oauth
=
config
.
oauth
;
$scope
.
oauthEnabled
=
_
.
keys
(
config
.
oauth
).
length
>
0
;
$scope
.
allowUserPassLogin
=
config
.
allowUserPassLogin
;
$scope
.
genericOAuthEnabled
=
config
.
genericOAuthEnabled
;
$scope
.
oauthProviderName
=
config
.
oauthProviderName
;
$scope
.
disableUserSignUp
=
config
.
disableUserSignUp
;
$scope
.
loginHint
=
config
.
loginHint
;
...
...
public/app/partials/login.html
View file @
e5fc4332
...
...
@@ -51,20 +51,20 @@
<div
class=
"clearfix"
></div>
<div
class=
"login-oauth text-center"
ng-show=
"oauthEnabled"
>
<a
class=
"btn btn-large btn-google"
href=
"login/google"
target=
"_self"
ng-if=
"
googleAuthEnabled
"
>
<a
class=
"btn btn-large btn-google"
href=
"login/google"
target=
"_self"
ng-if=
"
oauth.google
"
>
<i
class=
"fa fa-google"
></i>
with Google
</a>
<a
class=
"btn btn-large btn-github"
href=
"login/github"
target=
"_self"
ng-if=
"
githubAuthEnabled
"
>
<a
class=
"btn btn-large btn-github"
href=
"login/github"
target=
"_self"
ng-if=
"
oauth.github
"
>
<i
class=
"fa fa-github"
></i>
with Github
</a>
<a
class=
"btn btn-large btn-grafana-net"
href=
"login/grafananet"
target=
"_self"
ng-if=
"
grafanaNetAuthEnabled
"
>
<a
class=
"btn btn-large btn-grafana-net"
href=
"login/grafananet"
target=
"_self"
ng-if=
"
oauth.grafananet
"
>
with
<span>
Grafana.net
</span>
</a>
<a
class=
"btn btn-large btn-generic-oauth"
href=
"login/generic_oauth"
target=
"_self"
ng-if=
"
genericOAuthEnabled
"
>
<a
class=
"btn btn-large btn-generic-oauth"
href=
"login/generic_oauth"
target=
"_self"
ng-if=
"
oauth.generic_oauth
"
>
<i
class=
"fa fa-gear"
></i>
with {{oauth
ProviderName || "OAuth 2"
}}
with {{oauth
.generic_oauth.name
}}
</a>
</div>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment