diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-22 10:55:37 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-04-22 10:55:37 +0200 |
| commit | f76e87fa5ec30c416a562c4b29689f6a3e29458c (patch) | |
| tree | 1c4a0ef097a354dd61330c7bd7c09d4fad7c2f0f /src/oauth.go | |
| parent | 297dafbd45cd27165048262ef8ad00a8cb3e2b06 (diff) | |
Servers: Add initial support for multiple using a map
Diffstat (limited to 'src/oauth.go')
| -rw-r--r-- | src/oauth.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/oauth.go b/src/oauth.go index cb13d19..263690e 100644 --- a/src/oauth.go +++ b/src/oauth.go @@ -220,7 +220,7 @@ func (oauth *OAuth) Callback(w http.ResponseWriter, req *http.Request) { // It returns the authurl for the browser and an error if present func (eduvpn *VPNState) InitializeOAuth() error { if !eduvpn.HasTransition(OAUTH_STARTED) { - return errors.New("Failed starting oauth, invalid state") + return errors.New(fmt.Sprintf("Failed starting oauth, invalid state %s", eduvpn.FSM.Current.String())) } // Generate the state state, stateErr := genState() @@ -245,7 +245,11 @@ func (eduvpn *VPNState) InitializeOAuth() error { "redirect_uri": "http://127.0.0.1:8000/callback", } - authURL, urlErr := HTTPConstructURL(eduvpn.Server.Endpoints.API.V3.Authorization, parameters) + server, serverErr := eduvpn.Servers.GetCurrentServer() + if serverErr != nil { + return errors.New("OAuth Initialize no server found") + } + authURL, urlErr := HTTPConstructURL(server.Endpoints.API.V3.Authorization, parameters) if urlErr != nil { // shouldn't happen panic(urlErr) @@ -253,7 +257,7 @@ func (eduvpn *VPNState) InitializeOAuth() error { // Fill the struct with the necessary fields filled for the next call to getting the HTTP client oauthSession := OAuthExchangeSession{ClientID: eduvpn.Name, State: state, Verifier: verifier} - eduvpn.Server.OAuth = OAuth{TokenURL: eduvpn.Server.Endpoints.API.V3.Token, Session: oauthSession} + server.OAuth = OAuth{TokenURL: server.Endpoints.API.V3.Token, Session: oauthSession} eduvpn.GoTransitionWithData(OAUTH_STARTED, authURL) return nil } @@ -263,7 +267,11 @@ func (eduvpn *VPNState) FinishOAuth() error { if !eduvpn.HasTransition(AUTHENTICATED) { return errors.New("invalid state to finish oauth") } - tokenErr := eduvpn.Server.OAuth.getTokensWithCallback() + server, serverErr := eduvpn.Servers.GetCurrentServer() + if serverErr != nil { + return errors.New("OAuth Initialize No server found") + } + tokenErr := server.OAuth.getTokensWithCallback() if tokenErr != nil { return tokenErr } |
