Tuesday, November 24, 2020

HTTPD 2.4 Location Basic Authentication

  1. Customize httpd configuration file

          <Location /restrict/contents>


             Require all denied


             AuthName "Protected Contents"

             AuthType Basic

             AuthUserFile /www/svn/etc/passwd


             <RequireAny>

                 #Require user google

                 Require valid-user

             </RequireAny>


          </Location>

  2. Create password file
    The password is encrypted with MD5, example: 5he#t?+lfRos07zonon7
    $ htpasswd /www/svn/etc/passwd google
  3. Restart/Reload httpd daemon
    # systemctl reload httpd
  4. Encrypt username:password for 'Authorization:' header

    $ echo google:5he#t?+lfRos07zonon7 | base64

    Z29vZ2xlOjVoZSN0PytsZlJvczA3em9ub243Cg==

  5. Call with curl
    curl --location --request POST 'https://www.goweekend.ca/restrict/contents' \
    --header 'X-Authorization-Role: AUTHENTICATED' \
    --header 'Authorization: Basic e3thdXRoLmFjY2Vzcy5rZXl9fTp7e2F1dGguYWNjZXNzLnNlY3JldH19' \
    -H 'Content-Type: application/json' -d '{ "userid":"00019317", "lastName":"Qin"}'

     


No comments:

Post a Comment