Blog | G5 Cyber Security

ADFS Authentication Without JavaScript

TL;DR

You can authenticate with Active Directory Federation Services (ADFS) without relying on JavaScript by using the standard WS-Federation protocol directly through server-side redirects and POST requests. This is useful for applications that don’t run in a browser or where JavaScript isn’t available or desirable.

Solution Guide

  1. Understand the WS-Federation Flow
  2. ADFS uses WS-Federation for authentication. The basic flow involves these steps:

We’ll be handling these steps programmatically on the server side.

  • Construct the Authentication Request
  • You need to create an HTTP GET request to your ADFS endpoint. The URL will typically look like this:

    https://your-adfs-server/adfs/ls/?wa=wsignin1.0&wtrealm=your-application-url

    You can add other parameters as needed, such as:

    Example in Python:

    import requests
    
    adfs_url = "https://your-adfs-server/adfs/ls/"
    realm = "https://your-application-url"
    redirect_url = f"{adfs_url}?wa=wsignin1.0&wtrealm={realm}"
    
    response = requests.get(redirect_url)
    print(response.url) # This will show the ADFS login page URL
  • Handle the Redirect from ADFS
  • After the user authenticates, ADFS will redirect them back to the wtrealm URL you specified.

    Example of extracting the token:

    from urllib.parse import urlparse, parse_qs
    
    redirect_url = request.url # Get the redirect URL from your web framework
    parsed_url = urlparse(redirect_url)
    query_params = parse_qs(parsed_url.query)
    
    token = query_params.get('wa', [None])[0]
    if token:
      print("Token received:", token)
  • Configure ADFS Relying Party Trust
  • You must configure a Relying Party Trust in ADFS for your application.

  • Validate the Token
  • Your application needs to validate the received token.

    Token validation libraries are available for most programming languages. For example, in .NET you can use IdentityModel.

    Exit mobile version