Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/oauth2-server

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/oauth2-server - npm Package Compare versions

Comparing version 0.0.29 to 3.0.0

oauth2-server/LICENSE

562

oauth2-server/index.d.ts

@@ -1,213 +0,235 @@

// Type definitions for Node OAuth2 Server
// Project: https://github.com/thomseddon/node-oauth2-server
// Definitions by: Robbie Van Gorkom <https://github.com/vangorra>
// Type definitions for Node OAuth2 Server 3.0
// Project: https://github.com/oauthjs/node-oauth2-server
// Definitions by: Robbie Van Gorkom <https://github.com/vangorra>,
// Charles Irick <https://github.com/cirick>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/* =================== USAGE ===================
import { RequestHandler } from "express";
import { Request } from "express";
import * as oauthserver from "oauth2-server";
var oauth = oauthserver();
/**
* Represents an OAuth2 server instance.
*/
declare class OAuth2Server {
static OAuth2Server: typeof OAuth2Server;
=============================================== */
/**
* Instantiates OAuth2Server using the supplied model
*
* @param options
*/
constructor(options: OAuth2Server.ServerOptions);
/**
* Authenticates a request.
*
* @param request
* @param response
* @param options
* @param callback
*/
authenticate(
request: OAuth2Server.Request,
response: OAuth2Server.Response,
options?: OAuth2Server.AuthenticateOptions,
callback?: OAuth2Server.Callback<OAuth2Server.Token>
): Promise<OAuth2Server.Token>;
/**
* Authorizes a token request.
*
* @param request
* @param response
* @param options
* @param callback
*/
authorize(
request: OAuth2Server.Request,
response: OAuth2Server.Response,
options?: OAuth2Server.AuthorizeOptions,
callback?: OAuth2Server.Callback<OAuth2Server.AuthorizationCode>
): Promise<OAuth2Server.AuthorizationCode>;
/**
* Retrieves a new token for an authorized token request.
*
* @param request
* @param response
* @param options
* @param callback
*/
token(
request: OAuth2Server.Request,
response: OAuth2Server.Response,
options?: OAuth2Server.TokenOptions,
callback?: OAuth2Server.Callback<OAuth2Server.Token>
): Promise<OAuth2Server.Token>;
}
import {RequestHandler} from "express";
import {Request} from "express";
declare namespace OAuth2Server {
/**
* Represents an incoming HTTP request.
*/
class Request {
body?: any;
headers?: { [key: string]: string; };
method?: string;
query?: { [key: string]: string; };
declare function o(config: o.Config): o.OAuth2Server;
declare namespace o {
interface OAuth2Server {
grant(): RequestHandler;
authorise(): any;
errorHandler(): any;
}
interface Config {
/**
* Model object
* Instantiates Request using the supplied options.
*
* @param options
*/
model: {};
constructor(options?: { [key: string]: any } | Express.Request);
/**
* grant types you wish to support, currently the module supports authorization_code,
* password, refresh_token and client_credentials
* Returns the specified HTTP header field. The match is case-insensitive.
*
* @param field
*/
grants: string[];
get(field: string): any | undefined;
/**
* If true errors will be logged to console. You may also pass a custom function, in
* which case that function will be called with the error as its first argument
* Default: false
* Checks if the request’s Content-Type HTTP header matches any of the given MIME types.
*
* @param types
*/
debug?: boolean;
is(types: string[]): string | false;
}
/**
* Life of access tokens in seconds
* If null, tokens will considered to never expire
* Default: 3600
*/
accessTokenLifetime?: number;
/**
* Represents an outgoing HTTP response.
*/
class Response {
body?: any;
headers?: { [key: string]: string; };
status?: number;
/**
* Life of refresh tokens in seconds
* If null, tokens will considered to never expire
* Default: 1209600
* Instantiates Response using the supplied options.
*
* @param options
*/
refreshTokenLifetime?: number;
constructor(options?: { [key: string]: any; } | Express.Response);
/**
* Life of auth codes in seconds
* Default: 30
* Returns the specified HTTP header field. The match is case-insensitive.
*
* @param field
*/
authCodeLifetime?: number;
get(field: string): any | undefined;
/**
* Regex to sanity check client id against before checking model. Note: the default
* just matches common client_id structures, change as needed
* Default: /^[a-z0-9-_]{3,40}$/i
* Sets the specified HTTP header field. The match is case-insensitive.
*
* @param field
* @param value
*/
clientIdRegex?: RegExp;
set(field: string, value: string): void;
/**
* If true, non grant errors will not be handled internally (so you can ensure a
* consistent format with the rest of your api)
* Redirects to the specified URL using 302 Found.
*
* @param url
*/
passthroughErrors?: boolean;
redirect(url: string): void;
}
interface ServerOptions extends AuthenticateOptions, AuthorizeOptions, TokenOptions {
/**
* If true, next will be called even if a response has been sent (you probably don't want this)
* Model object
*/
continueAfterResponse?: boolean;
model: AuthorizationCodeModel | ClientCredentialsModel | RefreshTokenModel | PasswordModel | ExtensionModel;
}
interface BaseModel {
interface AuthenticateOptions {
/**
*
* @param bearerToken - The bearer token (access token) that has been provided
* @param callback
* The scope(s) to authenticate.
*/
getAccessToken(bearerToken: string,
callback: GetAccessTokenCallback): void;
scope?: string | undefined;
/**
*
* @param clientId
* @param clientSecret - If null, omit from search query (only search by clientId)
* @param callback
* Set the X-Accepted-OAuth-Scopes HTTP header on response objects.
*/
getClient(clientId: string,
clientSecret: string,
callback: GetClientCallback): void;
addAcceptedScopesHeader?: boolean;
/**
*
* @param clientId
* @param grantType
* @param callback
* Set the X-OAuth-Scopes HTTP header on response objects.
*/
grantTypeAllowed(clientId: string,
grantType: string,
callback: GrantTypeAllowedCallback): void;
addAuthorizedScopesHeader?: boolean;
/**
*
* @param accessToken
* @param clientId
* @param expires
* @param user
* @param callback
* Allow clients to pass bearer tokens in the query string of a request.
*/
saveAccessToken(accessToken: string,
clientId: string,
expires: Date,
user: User,
callback: SaveAccessTokenCallback): void;
allowBearerTokensInQueryString?: boolean;
}
interface AuthorizationCodeModel extends BaseModel {
interface AuthorizeOptions {
/**
*
* @param authCode
* @param callback
* The authenticate handler
*/
getAuthCode(authCode: string,
callback: GetAuthCodeCallback): void;
authenticateHandler?: {};
/**
*
* @param authCode
* @param clientId
* @param expires
* @param user - Whatever was passed as user to the codeGrant function (see example)
* @param callback
* Allow clients to specify an empty state
*/
saveAuthCode(authCode: string,
clientId: string,
expires: Date,
user: User | string,
callback: SaveAuthCodeCallback): void;
}
allowEmptyState?: boolean;
interface PasswordModel extends BaseModel {
/**
*
* @param username
* @param password
* @param callback
* Lifetime of generated authorization codes in seconds (default = 5 minutes).
*/
getUser(username: string,
password: string,
callback: GetUserCallback): void;
authorizationCodeLifetime?: number;
}
interface RefreshTokenModel extends BaseModel {
interface TokenOptions {
/**
*
* @param refreshToken
* @param clientId
* @param expires
* @param user
* @param callback
* Lifetime of generated access tokens in seconds (default = 1 hour)
*/
saveRefreshToken(refreshToken: string,
clientId: string,
expires: Date,
user: User,
callback: SaveRefreshTokenCallback): void;
accessTokenLifetime?: number;
/**
*
* @param refreshToken - The bearer token (refresh token) that has been provided
* @param callback
* Lifetime of generated refresh tokens in seconds (default = 2 weeks)
*/
getRefreshToken(refreshToken: string,
callback: GetRefreshTokenCallback): void;
refreshTokenLifetime?: number;
/**
* The spec does not actually require that you revoke the old token - hence this is
* optional (Last paragraph: http://tools.ietf.org/html/rfc6749#section-6)
* @param refreshToken
* @param callback
* Allow extended attributes to be set on the returned token
*/
revokeRefreshToken?(refreshToken: string,
callback: RevokeRefreshTokenCallback): void;
allowExtendedTokenAttributes?: boolean;
/**
* Require a client secret. Defaults to true for all grant types.
*/
requireClientAuthentication?: {};
/**
* Always revoke the used refresh token and issue a new one for the refresh_token grant.
*/
alwaysIssueNewRefreshToken?: boolean;
}
interface ExtensionModel extends BaseModel {
/**
* Represents a generic callback structure for model callbacks
*/
type Callback<T> = (err?: any, result?: T) => void;
/**
* For returning falsey parameters in cases of failure
*/
type Falsey = '' | 0 | false | null | undefined;
interface BaseModel {
/**
* Invoked to generate a new access token.
*
* @param grantType
* @param req
* @param client
* @param user
* @param scope
* @param callback
*/
extendedGrant(grantType: string,
req: Request,
callback: ExtendedGrantCallback): void;
}
generateAccessToken?(client: Client, user: User, scope: string, callback?: Callback<string>): Promise<string>;
interface ClientCredentialsModel extends BaseModel {
/**
* Invoked to retrieve a client using a client id or a client id/client secret combination, depending on the grant type.
*

@@ -218,207 +240,231 @@ * @param clientId

*/
getUserFromClient(clientId: string,
clientSecret: string,
callback: GetUserFromClientCallback): void;
getClient(clientId: string, clientSecret: string, callback?: Callback<Client | Falsey>): Promise<Client | Falsey>;
/**
* Invoked to save an access token and optionally a refresh token, depending on the grant type.
*
* @param type - accessToken or refreshToken
* @param req - The current express request
* @param token
* @param client
* @param user
* @param callback
*/
generateToken?(type: string,
req: Request,
callback: GenerateTokenCallback): void;
saveToken(token: Token, client: Client, user: User, callback?: Callback<Token>): Promise<Token>;
}
interface GenerateTokenCallback {
interface RequestAuthenticationModel {
/**
* Invoked to retrieve an existing access token previously saved through Model#saveToken().
*
* @param error - Truthy to indicate an error
* @param token - string indicates success
* null indicates to revert to the default token generator
* object indicates a reissue (i.e. will not be passed to saveAccessToken/saveRefreshToken)
* Must contain the following keys (if object):
* string accessToken OR refreshToken dependant on type
* @param accessToken
* @param callback
*/
(error: any, token: string | Object): void;
}
getAccessToken(accessToken: string, callback?: Callback<Token>): Promise<Token>;
interface GetUserFromClientCallback {
/**
* Invoked during request authentication to check if the provided access token was authorized the requested scopes.
*
* @param error - Truthy to indicate an error
* @param user - The user retrieved from storage or falsey to indicate an invalid user
* Saved in req.user
* @param token
* @param scope
* @param callback
*/
(error: any, user: User): void;
verifyScope(token: Token, scope: string, callback?: Callback<boolean>): Promise<boolean>;
}
interface ExtendedGrantCallback {
interface AuthorizationCodeModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to generate a new refresh token.
*
* @param error - Truthy to indicate an error
* @param supported - Whether you support the grant type
* @param user - The user retrieved from storage or falsey to indicate an invalid user
* Saved in req.user
* @param client
* @param user
* @param scope
* @param callback
*/
(error: any, supported: boolean, user: User): void;
}
generateRefreshToken?(client: Client, user: User, scope: string, callback?: Callback<string>): Promise<string>;
interface RevokeRefreshTokenCallback {
/**
* Truthy to indicate an error
* @param error
* Invoked to generate a new authorization code.
*
* @param callback
*/
(error: any): void;
}
generateAuthorizationCode?(callback?: Callback<string>): Promise<string>;
interface GetRefreshTokenCallback {
/**
* Invoked to retrieve an existing authorization code previously saved through Model#saveAuthorizationCode().
*
* @param error - Truthy to indicate an error
* @param refreshToken - The refresh token retrieved form storage or falsey to indicate invalid refresh token
* @param authorizationCode
* @param callback
*/
(error: any, refreshToken: RefreshToken): void;
}
getAuthorizationCode(authorizationCode: string, callback?: Callback<AuthorizationCode>): Promise<AuthorizationCode>;
interface SaveRefreshTokenCallback {
/**
* Invoked to save an authorization code.
*
* @param error - Truthy to indicate an error
* @param code
* @param client
* @param user
* @param callback
*/
(error: any): void;
}
saveAuthorizationCode(code: AuthorizationCode, client: Client, user: User, callback?: Callback<AuthorizationCode>): Promise<AuthorizationCode>;
interface GetUserCallback {
/**
* Invoked to revoke an authorization code.
*
* @param error - Truthy to indicate an error
* @param user - The user retrieved from storage or falsey to indicate an invalid user
* Saved in req.user
* @param code
* @param callback
*/
(error: any, user: User): void;
}
revokeAuthorizationCode(code: AuthorizationCode, callback?: Callback<boolean>): Promise<boolean>;
interface SaveAuthCodeCallback {
/**
* Invoked to check if the requested scope is valid for a particular client/user combination.
*
* @param error - Truthy to indicate an error
* @param user
* @param client
* @param string
* @param callback
*/
(error: any): void;
validateScope?(user: User, client: Client, scope: string, callback?: Callback<string[] | Falsey>): Promise<string[] | Falsey>;
}
interface GetAuthCodeCallback {
interface PasswordModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to generate a new refresh token.
*
* @param error - Truthy to indicate an error
* @param authCode - The authorization code retrieved form storage or falsey to indicate invalid code
* @param client
* @param user
* @param scope
* @param callback
*/
(error: String, authCode: AuthCode): void
}
generateRefreshToken?(client: Client, user: User, scope: string, callback?: Callback<string>): Promise<string>;
interface SaveAccessTokenCallback {
/**
* Invoked to retrieve a user using a username/password combination.
*
* @param error - Truthy to indicate an error
* @param username
* @param password
* @param callback
*/
(error: any): void;
}
getUser(username: string, password: string, callback?: Callback<User | Falsey>): Promise<User | Falsey>;
interface GetAccessTokenCallback {
/**
* Invoked to check if the requested scope is valid for a particular client/user combination.
*
* @param error - Truthy to indicate an error
* @param accessToken - The access token retrieved form storage or falsey to indicate invalid access token
* @param user
* @param client
* @param string
* @param callback
*/
(error: any, accessToken: AccessToken): void;
validateScope?(user: User, client: Client, scope: string, callback?: Callback<string[] | Falsey>): Promise<string[] | Falsey>;
}
interface GetClientCallback {
interface RefreshTokenModel extends BaseModel, RequestAuthenticationModel {
/**
* Invoked to generate a new refresh token.
*
* @param error - Truthy to indicate an error
* @param client - The client retrieved from storage or falsey to indicate an invalid client
* Saved in req.client
* @param client
* @param user
* @param scope
* @param callback
*/
(error: any, client: Client): void;
}
generateRefreshToken?(client: Client, user: User, scope: string, callback?: Callback<string>): Promise<string>;
interface GrantTypeAllowedCallback {
/**
* Invoked to retrieve an existing refresh token previously saved through Model#saveToken().
*
* @param error - Truthy to indicate an error
* @param allowed - Indicates whether the grantType is allowed for this clientId
* @param refreshToken
* @param callback
*/
(error: any, allowed: boolean): void;
}
getRefreshToken(refreshToken: string, callback?: Callback<RefreshToken>): Promise<RefreshToken>;
interface RefreshToken {
/**
* client id associated with this token
* Invoked to revoke a refresh token.
*
* @param token
* @param callback
*/
clientId: string;
revokeToken(token: Token, callback?: Callback<boolean>): Promise<boolean>;
}
interface ClientCredentialsModel extends BaseModel, RequestAuthenticationModel {
/**
* The date when it expires
* null to indicate the token never expires
* Invoked to retrieve the user associated with the specified client.
*
* @param client
* @param callback
*/
expires: Date;
getUserFromClient(client: Client, callback?: Callback<User | Falsey>): Promise<User | Falsey>;
/**
* Invoked to check if the requested scope is valid for a particular client/user combination.
*
* @param user
* @param client
* @param string
* @param callback
*/
userId: string;
validateScope?(user: User, client: Client, scope: string, callback?: Callback<string[] | Falsey>): Promise<string[] | Falsey>;
}
interface AuthCode {
/**
* client id associated with this auth code
*/
clientId: string;
interface ExtensionModel extends BaseModel, RequestAuthenticationModel {}
/**
* The date when it expires
*/
expires: Date;
/**
* The userId
*/
userId: string;
}
/**
* An interface representing the user.
* A user object is completely transparent to oauth2-server and is simply used as input to model functions.
*/
interface User {
id: string;
[key: string]: any;
}
/**
* An interface representing the client and associated data
*/
interface Client {
clientId: string;
id: string;
redirectUris?: string[];
grants: string[];
accessTokenLifetime?: number;
refreshTokenLifetime?: number;
[key: string]: any;
}
/**
* authorization_code grant type only
*/
/**
* An interface representing the authorization code and associated data.
*/
interface AuthorizationCode {
authorizationCode: string;
expiresAt: Date;
redirectUri: string;
scope?: string;
client: Client;
user: User;
[key: string]: any;
}
interface AccessToken {
/**
* The date when it expires
* null to indicate the token never expires
*/
expires: Date;
/**
* An interface representing the token(s) and associated data.
*/
interface Token {
accessToken: string;
accessTokenExpiresAt?: Date;
refreshToken?: string;
refreshTokenExpiresAt?: Date;
scope?: string;
client: Client;
user: User;
[key: string]: any;
}
/**
* If a user key exists, this is saved as req.user
*/
user?: User;
/**
* If a user key exists, this is saved as req.user
* Otherwise a userId key must exist, which is saved in req.user.id
*/
userId?: string;
/**
* An interface representing the refresh token and associated data.
*/
interface RefreshToken {
refreshToken: string;
refreshTokenExpiresAt?: Date;
scope?: string;
client: Client;
user: User;
[key: string]: any;
}
}
export = o;
export = OAuth2Server;
{
"name": "@types/oauth2-server",
"version": "0.0.29",
"version": "3.0.0",
"description": "TypeScript definitions for Node OAuth2 Server",
"license": "MIT",
"author": "Robbie Van Gorkom <https://github.com/vangorra>",
"contributors": [
{
"name": " Robbie Van Gorkom",
"url": "https://github.com/vangorra"
},
{
"name": "Charles Irick",
"url": "https://github.com/cirick"
}
],
"main": "",

@@ -16,4 +25,5 @@ "repository": {

},
"typings": "index.d.ts",
"typesPublisherContentHash": "37726b58207065cd11e03ef444be1e19869adbb994b68a30aded0ecf4e24a048"
"peerDependencies": {},
"typesPublisherContentHash": "43a633d974b6f7955e2f5aa55f6234878c113b5d23e2f98f1f9526cf4c9ed62a",
"typeScriptVersion": "2.0"
}

@@ -5,15 +5,13 @@ # Installation

# Summary
This package contains type definitions for Node OAuth2 Server (https://github.com/thomseddon/node-oauth2-server).
This package contains type definitions for Node OAuth2 Server (https://github.com/oauthjs/node-oauth2-server).
# Details
Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/types-2.0/oauth2-server
Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/oauth2-server
Additional Details
* Last updated: Mon, 19 Sep 2016 17:28:59 GMT
* File structure: ProperModule
* Library Dependencies: none
* Module Dependencies: express
* Global values: o
* Last updated: Fri, 23 Jun 2017 14:03:04 GMT
* Dependencies: express
* Global values: none
# Credits
These definitions were written by Robbie Van Gorkom <https://github.com/vangorra>.
These definitions were written by Robbie Van Gorkom <https://github.com/vangorra>, Charles Irick <https://github.com/cirick>.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc