> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jwtauth.pro/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Get started quickly with JWT Authentication Pro

This guide assumes you have already installed and configured JWT Auth Pro. If you haven't, please follow the [Installation Guide](/introduction/installation) first.

## Authentication Flow

### 1. Get a Token

To authenticate a user and get a JWT token:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    https://your-site.com/wp-json/jwt-auth/v1/token \
    -H "Content-Type: application/json" \
    -d '{"username": "your-username", "password": "your-password"}'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://your-site.com/wp-json/jwt-auth/v1/token', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      username: 'your-username',
      password: 'your-password'
    })
  });

  const auth = await response.json();
  // Store auth.token and auth.refresh_token securely
  ```

  ```php PHP - WordPress theme={null}
  $response = wp_remote_post( rest_url('jwt-auth/v1/token'), [
    'headers' => ['Content-Type' => 'application/json'],
    'body' => json_encode([
      'username' => 'your-username',
      'password' => 'your-password'
    ])
  ]);

  if ( is_wp_error( $response ) ) {
    // Handle error
    $error_message = $response->get_error_message();
  } else {
    $auth = json_decode( wp_remote_retrieve_body( $response ) );
    // Store $auth->token and $auth->refresh_token securely
  }
  ```
</CodeGroup>

### 2. Use the Token

Make authenticated requests using the token. Here's an example using the WordPress `/me` endpoint to get the current user's data:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET \
    https://your-site.com/wp-json/wp/v2/users/me \
    -H "Authorization: Bearer YOUR-JWT-TOKEN"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://your-site.com/wp-json/wp/v2/users/me', {
    headers: {
      'Authorization': `Bearer ${token}`
    }
  });

  const user = await response.json();
  // Access user data: user.id, user.name, user.email, etc.
  ```

  ```php PHP - WordPress theme={null}
  $response = wp_remote_get( rest_url('wp/v2/users/me'), [
    'headers' => [
      'Authorization' => 'Bearer ' . $token
    ]
  ]);

  if ( is_wp_error( $response ) ) {
    // Handle error
    $error_message = $response->get_error_message();
  } else {
    $user = json_decode( wp_remote_retrieve_body( $response ) );
    // Access user data: $user->id, $user->name, $user->email, etc.
  }
  ```
</CodeGroup>

### 3. Refresh Token

When the access token expires, use the refresh token to get a new one:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    https://your-site.com/wp-json/jwt-auth/v1/token/refresh \
    -H "Content-Type: application/json" \
    -d '{"refresh_token": "YOUR-REFRESH-TOKEN"}'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://your-site.com/wp-json/jwt-auth/v1/token/refresh', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      refresh_token: refreshToken
    })
  });

  const newAuth = await response.json();
  // Update stored tokens
  ```

  ```php PHP - WordPress theme={null}
  $response = wp_remote_post( rest_url('jwt-auth/v1/token/refresh'), [
    'headers' => ['Content-Type' => 'application/json'],
    'body' => json_encode([
      'refresh_token' => $refresh_token
    ])
  ]);

  if ( is_wp_error( $response ) ) {
    // Handle error
    $error_message = $response->get_error_message();
  } else {
    $auth = json_decode( wp_remote_retrieve_body( $response ) );
    // Update stored tokens with $auth->token and $auth->refresh_token
  }
  ```
</CodeGroup>

### 4. Revoke Token (Logout)

When a user logs out or you need to invalidate a token, use the revoke endpoint:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    https://your-site.com/wp-json/jwt-auth/v1/token/revoke \
    -H "Authorization: Bearer YOUR-JWT-TOKEN"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://your-site.com/wp-json/jwt-auth/v1/token/revoke', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`
    }
  });

  if (response.ok) {
    // Token revoked successfully, clear stored tokens
    localStorage.removeItem('token');
    localStorage.removeItem('refresh_token');
    // Redirect to login page or update UI
  }
  ```

  ```php PHP - WordPress theme={null}
  $response = wp_remote_post( rest_url('jwt-auth/v1/token/revoke'), [
    'headers' => [
      'Authorization' => 'Bearer ' . $token
    ]
  ]);

  if ( is_wp_error( $response ) ) {
    // Handle error
    $error_message = $response->get_error_message();
  } else {
    $result = json_decode( wp_remote_retrieve_body( $response ) );
    if ( $result->code === 'jwt_auth_token_revoked' ) {
      // Token revoked successfully, clear stored tokens
      // Redirect to login page or update session
    }
  }
  ```
</CodeGroup>

<Note>
  Remember to never expose your JWT secret key or store tokens in plain text. Always use secure storage methods appropriate for your platform.
</Note>
