Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(login): add flag to skip MAS-SSO login #477

Merged
merged 3 commits into from
Mar 24, 2021
Merged

Conversation

rkpattnaik780
Copy link
Contributor

@rkpattnaik780 rkpattnaik780 commented Mar 23, 2021

Description

Allow the user to skip logging in to MAS-SSO by passing a flag to the login command.

addresses #472

Verification Steps

  1. Pass the --skip-mas-login flag to the login command.

go run ./cmd/rhoas login --skip-mas-login

  1. Login to SSO from the browser.
  2. After successfully logging in, cli should print You are now logged in as "<username>"

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • Documentation added for the feature
  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small adjustments needed, check out the comments inline.

@@ -35,20 +35,22 @@ type SSOConfig struct {
// Execute runs an Authorization Code flow login
// enabling the user to log in to SSO and MAS-SSO in succession
// https://tools.ietf.org/html/rfc6749#section-4.1
func (a *AuthorizationCodeGrant) Execute(ctx context.Context, ssoCfg *SSOConfig, masSSOCfg *SSOConfig) (err error) {
func (a *AuthorizationCodeGrant) Execute(ctx context.Context, ssoCfg *SSOConfig, masSSOCfg *SSOConfig, skipMasSSOLogin bool) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The smaller the number of arguments in a function the better. We already have masSSOCfg which can be updated with something generic like skipAuth: Boolean

@@ -93,6 +94,7 @@ func NewLoginCmd(f *factory.Factory) *cobra.Command {
cmd.Flags().BoolVar(&opts.printURL, "print-sso-url", false, localizer.MustLocalizeFromID("login.flag.printSsoUrl"))
cmd.Flags().StringArrayVar(&opts.scopes, "scope", connection.DefaultScopes, localizer.MustLocalizeFromID("login.flag.scope"))
cmd.Flags().StringVarP(&opts.offlineToken, "token", "t", "", localizer.MustLocalizeFromID("login.flag.token"))
cmd.Flags().BoolVar(&opts.skipMasSSOLogin, "skip-mas-login", false, localizer.MustLocalizeFromID("login.flag.skipMasSSOLogin"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd.Flags().BoolVar(&opts.skipMasSSOLogin, "skip-mas-login", false, localizer.MustLocalizeFromID("login.flag.skipMasSSOLogin"))
cmd.Flags().BoolVar(&opts.skipMasSSOLogin, "skip-mas-auth", false, localizer.MustLocalizeFromID("login.flag.skipMasSSOLogin"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped auth suffix as login might be more familiar to the end user, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that we have the following flags: auth-url, mas-auth-url so it keeps with that pattern, i.e. it is obvious that skip-mas-auth means that mas-auth-url would not be used.

But I think you are correct, the command is called login, so skip-mas-login fits better with that.

err = c.masKeycloakClient.Logout(ctx, c.clientID, "", c.masRealm, c.MASToken.RefreshToken)
if err != nil {
return &AuthError{err}
if c.MASToken.RefreshToken != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that the MAS Refresh token will not be an empty string? Are we clearing these values when the --skip-mas-login flag is passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking of it now, we might MAS refresh token wont be empty if user logins twice, first without passing the skip flag and then with the skip flag. We should clear them while passing --skip-mas-login, thanks :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep :) When you log out it clears them, but if your session expires they persist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants