-
Notifications
You must be signed in to change notification settings - Fork 567
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 #661 from Versent/feat_browser_based_login
New browser based login using playright
- Loading branch information
Showing
6 changed files
with
101 additions
and
1 deletion.
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
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,85 @@ | ||
package browser | ||
|
||
import ( | ||
"errors" | ||
"net/url" | ||
|
||
"github.com/mxschmitt/playwright-go" | ||
"github.com/sirupsen/logrus" | ||
"github.com/versent/saml2aws/v2/pkg/cfg" | ||
"github.com/versent/saml2aws/v2/pkg/creds" | ||
) | ||
|
||
var logger = logrus.WithField("provider", "browser") | ||
|
||
// Client client for browser based Identity Provider | ||
type Client struct { | ||
} | ||
|
||
// New create new browser based client | ||
func New(idpAccount *cfg.IDPAccount) (*Client, error) { | ||
return &Client{}, nil | ||
} | ||
|
||
func (cl *Client) Authenticate(loginDetails *creds.LoginDetails) (string, error) { | ||
|
||
pw, err := playwright.Run() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// TODO: provide some overrides for this window | ||
launchOptions := playwright.BrowserTypeLaunchOptions{ | ||
Headless: playwright.Bool(false), | ||
} | ||
|
||
// currently using Chromium as it is widely supported for Identity providers | ||
// | ||
// this is a sandboxed browser window so password managers and addons are separate | ||
browser, err := pw.Chromium.Launch(launchOptions) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
page, err := browser.NewPage() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
logger.WithField("URL", loginDetails.URL).Info("opening browser") | ||
|
||
if _, err := page.Goto(loginDetails.URL); err != nil { | ||
return "", err | ||
} | ||
|
||
r := page.WaitForRequest("https://signin.aws.amazon.com/saml") | ||
data, err := r.PostData() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
values, err := url.ParseQuery(data) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
logger.Info("clean up browser") | ||
|
||
if err = browser.Close(); err != nil { | ||
return "", err | ||
} | ||
if err = pw.Stop(); err != nil { | ||
return "", err | ||
} | ||
|
||
return values.Get("SAMLResponse"), nil | ||
} | ||
|
||
func (cl *Client) Validate(loginDetails *creds.LoginDetails) error { | ||
|
||
if loginDetails.URL == "" { | ||
return errors.New("empty URL") | ||
} | ||
|
||
return 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
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