npm package: @identic-plus/tactic
Description: An abstract class implementing Identic's tactic API. Forked from passport-strategy.
Author: Daxton Garrard
Latest version: 0.1.0

# @identic-plus/tactic

An abstract class implementing Identic's tactic API.
Forked from Jared Hanson's [passport-strategy](https://www.npmjs.com/package/passport-strategy), rewritten in TypeScript, and modified to allow async function usage.

## Install

```sh
npm install @identic-plus/tactic
```

## Usage

This module exports an abstract `Tactic` class that is intended to be
extended when implementing concrete authentication tactics.  Once
implemented, such tactics can be used by applications that utilize Identic
middleware for authentication.

#### Extend Tactic

Create a new `CustomTactic` class which inherits from `Tactic`:

##### TypeScript
```typescript
import Tactic from "@identic-plus/tactic";

class CustomTactic extends Tactic {
  constructor() {
    super();
  }
}
```
##### JavaScript
```javascript
import { Tactic } from "@identic-plus/tactic";

class CustomTactic extends Tactic {
  constructor() {
    super();
  }
}
```

#### Implement Authentication

Implement `authenticate()`, performing the necessary operations required by the
authentication scheme or protocol being implemented.

##### TypeScript
```typescript
// class CustomTactic
async authenticate(req: Express.Request, options?: any): Promise<any> {
  // TODO: authenticate request
}
```
##### JavaScript
```javascript
// class CustomTactic
async authenticate(req, options) {
  // TODO: authenticate request
}
```

#### Augmented Methods
The Tactic.authenticate method is called on an instance of this Tactic that's augmented with the following action functions.  
These action functions are bound via closure the the request/response pair.  
The end goal of the tactic is to invoke *one* of these action methods, in
order to indicate successful or failed authentication, redirect to a
third-party identity provider, etc.

* [.success(user, info)](#tacticsuccessuser-info)
* [.fail(challenge, status)](#tacticfailchallenge-status)
* [.redirect(url, status)](#tacticredirecturl-status)
* [.pass()](#tacticpass)
* [.error(err)](#tacticerrorerr)


##### tactic.success(user, info)
Authenticate `user`, with optional `info`.

Tactics should call this function to successfully authenticate a
user.  `user` should be supplied by the application after it
has been given an opportunity to verify credentials.  `info` is an
optional argument containing additional user information.  This is
useful for third-party authentication tactics to pass profile
details.

**Kind**: instance method of [Tactic](#extend-tactic)  
**Api**: public  

| Param | Type |
| --- | --- |
| user | Express.User (Object) | 
| info | Object | 


##### tactic.fail(challenge, status)
Fail authentication, with optional `challenge` and `status`, defaulting
to 401.

Tactics should call this function to fail an authentication attempt.

**Kind**: instance method of [Tactic](#extend-tactic)  
**Api**: public  

| Param | Type |
| --- | --- |
| challenge | TacticFailure \| String \| Number | 
| status | Number | 



##### tactic.redirect(url, status)
Redirect to `url` with optional `status`, defaulting to 302.

Tactics should call this function to redirect the user (via their
user agent) to a third-party website for authentication.

**Kind**: instance method of [Tactic](#extend-tactic)  
**Api**: public  

| Param | Type |
| --- | --- |
| url | String | 
| status | Number | 


##### tactic.pass()
Pass without making a success or fail decision.

Under most circumstances, Tactics should not need to call this
function.  It exists primarily to allow previous authentication state
to be restored, for example from an HTTP session.

**Kind**: instance method of [Tactic](#extend-tactic)  
**Api**: public  

##### tactic.error(err)
Internal error while performing authentication.

Tactics should call this function when an internal error occurs
during the process of performing authentication; for example, if the
user directory is not available.

**Kind**: instance method of [Tactic](#extend-tactic)  
**Api**: public  

| Param | Type |
| --- | --- |
| err | Error \| any | 



## Related Modules

- [passport](https://github.com/jaredhanson/passport) — the original Passport authentication library created by Jared Hanson
- [passport-strategy](https://github.com/jaredhanson/passport-strategy) — the Passport Strategy helper library created by Jared Hanson
- [chai-passport-strategy](https://github.com/jaredhanson/chai-passport-strategy) — helpers for testing Passport strategies (which are compatible with Identic tactics) with the Chai assertion library

## Build From Source

```sh
mkdir identic-tactic
cd identic-tactic
git clone https://github.com/identic-plus/tactic.git
npm install
npm run build
```

## Tests

```sh
npm install
npm test
```

## Credits

  - [Daxton Garrard](https://github.com/daxgar1)
  - [Jared Hanson](http://github.com/jaredhanson)

## License

[The MIT License](http://opensource.org/licenses/MIT)

Copyright (c) 2025 Daxton Garrard

Copyright (c) 2011-2014 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>