-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9ecc5e
commit 83d69b9
Showing
7 changed files
with
186 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,52 @@ | ||
[gapps.consumer] | ||
servicekeyfile = "gapps.json" | ||
adminaccount = "[email protected]" | ||
servicekeyfile = "gapps.json" | ||
adminaccount = "[email protected]" | ||
|
||
[gapps.provider] | ||
servicekeyfile = "gapps.json" | ||
adminaccount = "[email protected]" | ||
servicekeyfile = "gapps.json" | ||
adminaccount = "[email protected]" | ||
|
||
[gamma.provider] | ||
apiKey = "key" | ||
url = "http://localhost:8081" | ||
apiKey = "key" | ||
url = "http://gamma-backend:8081" | ||
|
||
[auth.provider] | ||
apiKey = "key" | ||
url = "http://gamma-mock:8081" | ||
|
||
[additions] | ||
file = "additions.json" | ||
|
||
[ldap] | ||
url = "ldap.mydomain.ex:636" | ||
servername = "mydomain.ex" | ||
user = "cn=admin,dc=mydomain,dc=ex" | ||
password = "PASSWORD" | ||
custom = ["fkit", "kit"] | ||
url = "ldap.mydomain.ex:636" | ||
servername = "mydomain.ex" | ||
user = "cn=admin,dc=mydomain,dc=ex" | ||
password = "PASSWORD" | ||
custom = ["fkit", "kit"] | ||
|
||
[ldap.groups] | ||
basedn = "ou=groups,dc=mydomain,dc=ex" | ||
filter = "(|(objectClass=itGroup)(objectClass=itPosition))" | ||
attibutes = ["cn", "displayName", "mail", "member"] | ||
basedn = "ou=groups,dc=mydomain,dc=ex" | ||
filter = "(|(objectClass=itGroup)(objectClass=itPosition))" | ||
attibutes = ["cn", "displayName", "mail", "member"] | ||
|
||
[ldap.users] | ||
basedn = "ou=people,dc=mydomain,dc=ex" | ||
filter = "(&(objectClass=chalmersstudent))" | ||
attibutes = ["uid", "mail"] | ||
basedn = "ou=people,dc=mydomain,dc=ex" | ||
filter = "(&(objectClass=chalmersstudent))" | ||
attibutes = ["uid", "mail"] | ||
|
||
#### CUSTOM FILTERS #### | ||
[ldap.fkit] | ||
mail = "[email protected]" | ||
basedn = "ou=fkit,ou=groups,dc=mydomain,dc=ex" | ||
filter = "(&(objectClass=itGroup))" | ||
parent_filter = "(&(ou=%childRDN%))" | ||
attibutes = ["cn", "displayName", "mail"] | ||
mail = "[email protected]" | ||
basedn = "ou=fkit,ou=groups,dc=mydomain,dc=ex" | ||
filter = "(&(objectClass=itGroup))" | ||
parent_filter = "(&(ou=%childRDN%))" | ||
attibutes = ["cn", "displayName", "mail"] | ||
|
||
|
||
[ldap.kit] | ||
mail = "[email protected]" | ||
basedn = "ou=fkit,ou=groups,dc=mydomain,dc=ex" | ||
filter = "(&(objectClass=itGroup)(type=Committee))" | ||
parent_filter = "(&(ou=%childRDN%))" | ||
attibutes = ["cn", "displayName", "mail"] | ||
mail = "[email protected]" | ||
basedn = "ou=fkit,ou=groups,dc=mydomain,dc=ex" | ||
filter = "(&(objectClass=itGroup)(type=Committee))" | ||
parent_filter = "(&(ou=%childRDN%))" | ||
attibutes = ["cn", "displayName", "mail"] | ||
#### ============== #### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package auth | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/cthit/goldapps/internal/pkg/model" | ||
) | ||
|
||
type AuthService struct { | ||
apiKey string | ||
url string | ||
} | ||
|
||
//Creates a auth service which has the url to auth and the pre-shared key | ||
func CreateAuthService(apiKey string, url string) (AuthService, error) { | ||
return AuthService{ | ||
apiKey: apiKey, | ||
url: url, | ||
}, nil | ||
} | ||
|
||
//Executes a generic get request with api key | ||
func request(s *AuthService, endpoint string, response interface{}) error { | ||
req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", s.url, endpoint), nil) | ||
if err != nil { | ||
log.Println(err) | ||
return err | ||
} | ||
|
||
req.Header.Set("Authorization", fmt.Sprintf("pre-shared %s", s.apiKey)) | ||
|
||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
log.Println(err) | ||
return err | ||
} | ||
fmt.Printf("Request sent to: %s [key: %s] status %d\n", endpoint, s.apiKey, resp.StatusCode) | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Println(err) | ||
return err | ||
} | ||
|
||
err = json.Unmarshal(body, &response) | ||
if err != nil { | ||
log.Println(err) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s AuthService) GetGroups() ([]model.Group, error) { | ||
var groups []model.Group | ||
|
||
err := request(&s, "/api/goldapps/groups", &groups) | ||
if err != nil { | ||
log.Println(err) | ||
return nil, err | ||
} | ||
|
||
return groups, nil | ||
} | ||
|
||
func (s AuthService) GetUsers() ([]model.User, error) { | ||
var users []model.User | ||
|
||
err := request(&s, "/api/goldapps/users", &users) | ||
if err != nil { | ||
log.Println(err) | ||
return nil, err | ||
} | ||
|
||
return users, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters