-
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.
Merge branch 'main' into prod-business
- Loading branch information
Showing
27 changed files
with
451 additions
and
185 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 |
---|---|---|
@@ -1,20 +1,7 @@ | ||
package config | ||
|
||
import "fmt" | ||
|
||
type ApplicationSettings struct { | ||
Port uint16 `env:"PORT"` | ||
Host string `env:"HOST"` | ||
BaseUrl string `env:"BASE_URL"` | ||
PublicUrl string `env:"PUBLIC_URL"` | ||
} | ||
|
||
func (s *ApplicationSettings) ApplicationURL() string { | ||
var host string | ||
if s.Host == "127.0.0.1" { | ||
host = "localhost" | ||
} else { | ||
host = s.Host | ||
} | ||
return fmt.Sprintf("http://%s:%d", host, s.Port) | ||
PublicURL string `env:"PUBLIC_URL"` | ||
} |
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
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
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,64 @@ | ||
package msft_mobile | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"time" | ||
|
||
go_json "github.com/goccy/go-json" | ||
|
||
"github.com/GenerateNU/sac/backend/integrations/oauth/soth" | ||
"github.com/GenerateNU/sac/backend/utilities" | ||
) | ||
|
||
// Session is the implementation of `soth.Session` for accessing microsoftonline. | ||
// Refresh token not available for microsoft online: session size hit the limit of max cookie size | ||
type Session struct { | ||
AuthURL string | ||
AccessToken string | ||
ExpiresAt time.Time | ||
} | ||
|
||
// GetAuthURL will return the URL set by calling the `BeginAuth` function on the Microsoft provider. | ||
func (s Session) GetAuthURL() (string, error) { | ||
if s.AuthURL == "" { | ||
return "", errors.New(soth.NoAuthUrlErrorMessage) | ||
} | ||
|
||
return s.AuthURL, nil | ||
} | ||
|
||
// Authorize the session with Microsoft and return the access token to be stored for future use. | ||
func (s *Session) Authorize(provider soth.Provider, params soth.Params) (string, error) { | ||
p := provider.(*Provider) | ||
token, err := p.config.Exchange(soth.ContextForClient(utilities.Client()), params.Get("code")) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if !token.Valid() { | ||
return "", errors.New("invalid token received from provider") | ||
} | ||
|
||
s.AccessToken = token.AccessToken | ||
s.ExpiresAt = token.Expiry | ||
|
||
return token.AccessToken, err | ||
} | ||
|
||
// Marshal the session into a string | ||
func (s Session) Marshal() string { | ||
b, _ := go_json.Marshal(s) | ||
return string(b) | ||
} | ||
|
||
func (s Session) String() string { | ||
return s.Marshal() | ||
} | ||
|
||
// UnmarshalSession wil unmarshal a JSON string into a session. | ||
func (p *Provider) UnmarshalSession(data string) (soth.Session, error) { | ||
session := &Session{} | ||
err := go_json.NewDecoder(strings.NewReader(data)).Decode(session) | ||
return session, err | ||
} |
Oops, something went wrong.