Skip to content

Commit

Permalink
Merge pull request #400 from jmpsec/oauth-authentication
Browse files Browse the repository at this point in the history
Base for oauth authentication
  • Loading branch information
javuto committed Feb 10, 2024
2 parents e80c8f9 + a66cb30 commit c508563
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
35 changes: 35 additions & 0 deletions admin/oauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"log"

"github.com/jmpsec/osctrl/settings"
"github.com/spf13/viper"
)

// JSONConfigurationOAuth to keep all OAuth details for auth
type JSONConfigurationOAuth struct {
ClientID string `json:"clientid"`
ClientSecret string `json:"clientsecret"`
RedirectURL string `json:"redirecturl"`
Scopes []string `json:"scopes"`
EndpointURL string `json:"endpointurl"`
}

// Function to load the configuration file
func loadOAuth(file string) (JSONConfigurationOAuth, error) {
var cfg JSONConfigurationOAuth
log.Printf("Loading %s", file)
// Load file and read config
viper.SetConfigFile(file)
if err := viper.ReadInConfig(); err != nil {
return cfg, err
}
// OAuth values
oauthRaw := viper.Sub(settings.AuthOAuth)
if err := oauthRaw.Unmarshal(&cfg); err != nil {
return cfg, err
}
// No errors!
return cfg, nil
}
12 changes: 6 additions & 6 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const (

// Types of authentication
const (
AuthNone string = "none"
AuthJSON string = "json"
AuthDB string = "db"
AuthSAML string = "saml"
AuthJWT string = "jwt"
AuthOAuth2 string = "oauth2"
AuthNone string = "none"
AuthJSON string = "json"
AuthDB string = "db"
AuthSAML string = "saml"
AuthJWT string = "jwt"
AuthOAuth string = "oauth"
)

// Types of logging
Expand Down

0 comments on commit c508563

Please sign in to comment.