Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 287237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:42:27+00:00 2026-05-12T05:42:27+00:00

The answer to a previous question showed that Nexus implement a custom authentication helper

  • 0

The answer to a previous question showed that Nexus implement a custom authentication helper called “NxBASIC”.

How do I begin to implement a handler in python?


Update:

Implementing the handler per Alex’s suggestion looks to be the right approach, but fails trying to extract the scheme and realm from the authreq.
The returned value for authreq is:

str: NxBASIC realm="Sonatype Nexus Repository Manager API""

AbstractBasicAuthHandler.rx.search(authreq) is only returning a single tuple:

tuple: ('NxBASIC', '"', 'Sonatype Nexus Repository Manager API')

so scheme,realm = mo.groups() fails. From my limited regex knowledge it looks like the standard regex from AbstractBasicAuthHandler should match scheme and realm, but it seems not to.

The regex is:

rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+'
                'realm=(["\'])(.*?)\\2', re.I)

Update 2:
From inspection of AbstractBasicAuthHandler, the default processing is to do:

scheme, quote, realm = mo.groups()

Changing to this works. I now just need to set the password against the correct realm. Thanks Alex!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:42:28+00:00Added an answer on May 12, 2026 at 5:42 am

    If, as described, name and description are the only differences between this “NxBasic” and good old “Basic”, then you could essentially copy-paste-edit some code from urllib2.py (which unfortunately doesn’t expose the scheme name as easily overridable in itself), as follows (see urllib2.py‘s online sources):

    import urllib2
    
    class HTTPNxBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
    
        def http_error_auth_reqed(self, authreq, host, req, headers):
            # host may be an authority (without userinfo) or a URL with an
            # authority
            # XXX could be multiple headers
            authreq = headers.get(authreq, None)
            if authreq:
                mo = AbstractBasicAuthHandler.rx.search(authreq)
                if mo:
                    scheme, realm = mo.groups()
                    if scheme.lower() == 'nxbasic':
                        return self.retry_http_basic_auth(host, req, realm)
    
        def retry_http_basic_auth(self, host, req, realm):
            user, pw = self.passwd.find_user_password(realm, host)
            if pw is not None:
                raw = "%s:%s" % (user, pw)
                auth = 'NxBasic %s' % base64.b64encode(raw).strip()
                if req.headers.get(self.auth_header, None) == auth:
                    return None
                req.add_header(self.auth_header, auth)
                return self.parent.open(req)
            else:
                return None
    

    As you can see by inspection, I’ve just changed two strings from “Basic” to “NxBasic” (and the lowercase equivalents) from what’s in urrlib2.py (in the abstract basic auth handler superclass of the http basic auth handler class).

    Try using this version — and if it’s still not working, at least having it be your code can help you add print/logging statements, breakpoints, etc, to better understand what’s breaking and how. Best of luck! (Sorry I can’t help further but I don’t have any Nexus around to experiment with).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 165k
  • Answers 165k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are a couple of variants of a rename command,… May 12, 2026 at 12:33 pm
  • Editorial Team
    Editorial Team added an answer There is currently no way to build CLS-compliant assemblies from… May 12, 2026 at 12:33 pm
  • Editorial Team
    Editorial Team added an answer You might want to look at Google Protocol Buffers or… May 12, 2026 at 12:33 pm

Related Questions

A previous question showed a nice way of printing to a string. The answer
I've inherited a body of Visual C++ source that consists of about a dozen
This came up from this answer to a previous question of mine . Is
I have a web app (ASP.NET 2.0 C#)where I get data from an Oracle
I would be certain that this question addresses something that would have been brought

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.