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

Option to skip manual button press requirement if redmine_oauth only authentication method #32

Closed
col-panic opened this issue May 10, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@col-panic
Copy link

If password login is disabled, and oauth2 is the only login-method, could there be a "skip-press-button" option? Where I don't have to manually press the login button to trigger oauth2 authentication?

That is, a user that already has a valid session could directly access redmine and will be auto-logged in.

@Tomnm1
Copy link

Tomnm1 commented Sep 26, 2024

Here's my ready to use patch to AccountController which works fine, except for logout method, which is custumized for our use case which is Keycloak, I guess same could be done for other providers.

Also response to #33

require 'net/http'
require 'uri'

module AccountControllerPatch
  def self.included(base)
    base.class_eval do
      alias_method :original_login, :login
      alias_method :original_logout, :logout
      alias_method :original_register, :register
      alias_method :original_lost_password, :lost_password    

      def login
        if request.path == '/login'
          session[:back_url] = params[:back_url]
          redirect_to back_url.present? ? "/oauth?back_url=#{CGI.escape(back_url)}" : '/oauth'
        else
          original_login
        end
      end
      def register
        if request.path == '/account/register'
          redirect_to '/oauth'          
        else
          original_login
        end
      end
      def lost_password
        if request.path == '/account/lost_password'
          redirect_to '/oauth'
        else
          original_login
        end
      end
      def logout
        if User.current.logged?
          if session[:user_id]
            session.delete(:user_id)
          end
          cookies.delete :autologin
          User.current = nil
        end
        id_token = session[:id_token]
        keycloak_domain = "xxx"
        keycloak_realm = "xxx"
        keycloak_client_id = "xxx"
        post_logout_redirect_uri = CGI.escape("xxx")
        keycloak_logout_url = "#{keycloak_domain}/auth/realms/#{keycloak_realm}/protocol/openid-connect/logout?id_token_hint=#{id_token}&post_logout_redirect_uri=#{post_logout_redirect_uri}"
        redirect_to keycloak_logout_url and return
      end
    end
  end
end

unless AccountController.included_modules.include? AccountControllerPatch
  AccountController.send(:include, AccountControllerPatch)
end

picman added a commit that referenced this issue Sep 26, 2024
@picman
Copy link
Collaborator

picman commented Sep 26, 2024

I've implemented it as follows:

  • There is a new plugin's option OAuth login.
  • If set, a checkbox Autologin with OAuth provider is present in the login form.
  • If a user checks out the Autologin checkbox, they are automatically logged in via the set OAuth provider until they manually log out.

The behaviour is very similar to the Redmine's Autologin option in the login form.

picman added a commit that referenced this issue Sep 26, 2024
picman added a commit that referenced this issue Sep 26, 2024
@picman picman closed this as completed Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants