Authnest Developer Documentation

Getting Started

Welcome to Authnest, a powerful authentication solution for your B2B applications. Follow these steps to integrate Authnest into your project:

  1. Sign up for an Authnest developer account

    Visit the Authnest Developer page and create your developer account using your email address.

  2. Create a new app in the Authnest dashboard

    Once logged in, navigate to the dashboard and click on "Create New App". Provide a name for your app and basic information such as contact email, homepage URL, privacy policy URL, and terms of service URL.

  3. Configure your app settings and OAuth 2.0 clients

    In your app settings, you can configure:

    • Allowed domains and emails
    • Blocked domains and emails
    • Email provider restrictions
    • OAuth scopes
    • Custom profile fields

    Create an OAuth 2.0 client for your app by specifying the client name, authorized JavaScript origins, and redirect URIs.

  4. Integrate Authnest into your application

    Use the Authnest REST API to implement authentication in your application. See the API Reference section for more details.

  5. Add the "Continue with Authnest" button

    Include the Authnest login button in your application:

    <a href="https://authnest.com/oauth2/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&scope=openid%20email%20profile%20offline">
      <img src="https://authnest.com/authnest-logo.png" alt="Continue with Authnest" />
      Continue with Authnest
    </a>
              

    Note: Replace YOUR_CLIENT_ID and YOUR_REDIRECT_URI with your actual client ID and redirect URI.

Authentication Flow

Authnest uses the OAuth 2.0 protocol for authentication. Here's a detailed overview of the authentication flow:

  1. Redirect the user to the Authnest authorization endpoint

    Construct the authorization URL with your client ID, redirect URI, requested scopes, and optional parameters:

    https://authnest.com/oauth2/authorize?
      response_type=code&
      client_id=YOUR_CLIENT_ID&
      redirect_uri=YOUR_REDIRECT_URI&
      scope=openid%20email%20profile%20offline&
      state=RANDOM_STATE_VALUE
              

    Note: The state parameter is optional but recommended for security purposes. It helps prevent cross-site request forgery (CSRF) attacks.

  2. User selects their work email to authorize

    The user is presented with Authnest's login page, where they can select their work email to authorize access.

  3. Authnest redirects back to your app

    After successful authentication, Authnest redirects the user back to your specified redirect URI with an authorization code:

    YOUR_REDIRECT_URI?code=AUTHORIZATION_CODE&state=RANDOM_STATE_VALUE
              
  4. Exchange the authorization code for tokens

    Make a POST request to the token endpoint to exchange the authorization code for access and ID tokens:

    POST /oauth2/token HTTP/1.1
    Host: api.authnest.com
    Content-Type: application/x-www-form-urlencoded
    
    grant_type=authorization_code&
    client_id=YOUR_CLIENT_ID&
    client_secret=YOUR_CLIENT_SECRET&
    code=AUTHORIZATION_CODE&
    redirect_uri=YOUR_REDIRECT_URI
              
  5. Use the userinfo endpoint and decode the ID token

    You can retrieve user information in two ways:

    1. Call the userinfo endpoint using the access token:

              GET /oauth2/userinfo HTTP/1.1
              Host: api.authnest.com
              Authorization: Bearer ACCESS_TOKEN
                    
    2. Decode and verify the JWT ID token:

              // Example using a JWT library (implementation may vary)
              const decodedToken = jwt.verify(idToken, publicKey, { algorithms: ['RS256'] });
              console.log(decodedToken);
                    

      The decoded ID token contains claims about the authenticated user.

      Note: To obtain the public key for token verification, refer to the Public Key Retrieval section below.

Public Key Retrieval

To verify the JWT ID token, you need to get the public key:

  1. Fetch the JWKS (JSON Web Key Set) from the well-known endpoint:

        GET /.well-known/jwks.json HTTP/1.1
        Host: api.authnest.com
              
  2. Extract the public key from the JWKS response:

        // Example using a JWT library (implementation may vary)
        const jwks = await fetchJwks('https://api.authnest.com/.well-known/jwks.json');
        const key = jwks.keys.find(k => k.kid === decodedToken.header.kid);
        const publicKey = await jose.importJWK(key, key.alg);
        
        // Verify the ID token
        const { payload } = await jose.jwtVerify(idToken, publicKey);
        console.log(payload);
              

API Reference

OAuth 2.0 Endpoints

Token Endpoint

Use this endpoint to exchange an authorization code for access and ID tokens, or to refresh an access token.

POST /oauth2/token HTTP/1.1
Host: api.authnest.com
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
code=AUTHORIZATION_CODE&
redirect_uri=YOUR_REDIRECT_URI
      

For refreshing a token:

POST /oauth2/token HTTP/1.1
Host: api.authnest.com
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
refresh_token=REFRESH_TOKEN
      

Response:

{
  "access_token": "ACCESS_TOKEN",
  "token_type": "Bearer",
  "expires_in": 3600,
  "id_token": "ID_TOKEN",
  "refresh_token": "REFRESH_TOKEN"
}
      

User Info Endpoint

Retrieve information about the authenticated user using this endpoint.

GET /oauth2/userinfo HTTP/1.1
Host: api.authnest.com
Authorization: Bearer ACCESS_TOKEN
      

Response:

{
  "sub": "user_12345",
  "email": "[email protected]",
  "email_verified": true,
  "name": "John Doe",
  "given_name": "John",
  "family_name": "Doe",
  "picture": "https://example.com/photo.jpg",
  "locale": "en-US"
}
      

Token Info Endpoint

Get information about an access token or ID token.

GET /oauth2/tokeninfo?access_token=ACCESS_TOKEN HTTP/1.1
Host: api.authnest.com
      

Response:

{
  "iss": "https://authnest.com",
  "sub": "user_12345",
  "aud": "YOUR_CLIENT_ID",
  "exp": 1619876543,
  "iat": 1619872943,
  "scope": "openid email profile offline"
}
      

Token Revocation Endpoint

Use this endpoint to revoke an access token or refresh token.

POST /oauth2/revoke HTTP/1.1
Host: api.authnest.com
Content-Type: application/x-www-form-urlencoded

token=TOKEN_TO_REVOKE&
token_type_hint=access_token&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET
      

Parameters:

Response: HTTP 200 OK (empty response body on success)

Security Best Practices

To ensure the security of your application and user data, follow these best practices:

Support and Community

If you need help or want to connect with other developers using Authnest, you can: