-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from jmpsec/oauth-authentication
Base for oauth authentication
- Loading branch information
Showing
2 changed files
with
41 additions
and
6 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
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 | ||
} |
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