Skip to content

Commit c3011b1

Browse files
feat(typescript): export types (#266)
* feat(typescript): export types * docs: update ToC for README.md Co-authored-by: prettier-toc-me[bot] <56236715+prettier-toc-me[bot]@users.noreply.github.com>
1 parent 33f6faf commit c3011b1

File tree

3 files changed

+63
-23
lines changed

3 files changed

+63
-23
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [GitHub APP user authentication token with expiring disabled](#github-app-user-authentication-token-with-expiring-disabled)
3030
- [GitHub APP user authentication token with expiring enabled](#github-app-user-authentication-token-with-expiring-enabled)
3131
- [`auth.hook(request, route, parameters)` or `auth.hook(request, options)`](#authhookrequest-route-parameters-or-authhookrequest-options)
32+
- [Types](#types)
3233
- [Implementation details](#implementation-details)
3334
- [License](#license)
3435

@@ -1349,6 +1350,29 @@ const requestWithAuth = request.defaults({
13491350
});
13501351
```
13511352

1353+
## Types
1354+
1355+
```ts
1356+
import {
1357+
// strategy options
1358+
StrategyOptions,
1359+
// auth options
1360+
AuthOptions,
1361+
AppAuthOptions,
1362+
OAuthAppAuthOptions,
1363+
InstallationAuthOptions,
1364+
OAuthWebFlowAuthOptions,
1365+
OAuthDeviceFlowAuthOptions,
1366+
// authentication objects
1367+
Authentication,
1368+
AppAuthentication,
1369+
OAuthAppAuthentication,
1370+
InstallationAccessTokenAuthentication,
1371+
GitHubAppUserAuthentication,
1372+
GitHubAppUserAuthenticationWithExpiration,
1373+
} from "@octokit/auth-app";
1374+
```
1375+
13521376
## Implementation details
13531377

13541378
When creating a JSON Web Token, it sets the "issued at time" (iat) to 30s in the past as we have seen people running situations where the GitHub API claimed the iat would be in future. It turned out the clocks on the different machine were not in sync.

src/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ import { StrategyInterface, State, StrategyOptions } from "./types";
99
import { VERSION } from "./version";
1010

1111
export { createOAuthUserAuth } from "@octokit/auth-oauth-user";
12+
export {
13+
// strategy options
14+
StrategyOptions,
15+
// auth options
16+
AuthOptions,
17+
AppAuthOptions,
18+
OAuthAppAuthOptions,
19+
InstallationAuthOptions,
20+
OAuthWebFlowAuthOptions,
21+
OAuthDeviceFlowAuthOptions,
22+
// authentication objects
23+
Authentication,
24+
AppAuthentication,
25+
OAuthAppAuthentication,
26+
InstallationAccessTokenAuthentication,
27+
GitHubAppUserAuthentication,
28+
GitHubAppUserAuthenticationWithExpiration,
29+
} from "./types";
1230

1331
export const createAppAuth: StrategyInterface = function createAppAuth(
1432
options: StrategyOptions

src/types.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as OctokitTypes from "@octokit/types";
22
import LRUCache from "lru-cache";
3-
import {
4-
GitHubAuthInterface,
5-
AppAuthentication as OAuthAppAuthentication,
6-
GitHubAppUserAuthentication,
7-
GitHubAppUserAuthenticationWithExpiration,
8-
AppAuthOptions as OAuthAppAuthOptions,
9-
WebFlowAuthOptions,
10-
GitHubAppDeviceFlowAuthOptions,
11-
} from "@octokit/auth-oauth-app";
3+
// import {
4+
// GitHubAuthInterface as OAuthAppGitHubAuthInterface,
5+
// AppAuthentication as OAuthAppAuthentication,
6+
// GitHubAppUserAuthentication,
7+
// GitHubAppUserAuthenticationWithExpiration,
8+
// AppAuthOptions as OAuthAppAuthOptions,
9+
// WebFlowAuthOptions,
10+
// GitHubAppDeviceFlowAuthOptions,
11+
// } from "@octokit/auth-oauth-app";
12+
import * as OAuthAppAuth from "@octokit/auth-oauth-app";
1213

1314
export type AnyResponse = OctokitTypes.OctokitResponse<any>;
1415
export type EndpointDefaults = OctokitTypes.EndpointDefaults;
@@ -70,6 +71,10 @@ export type InstallationAccessTokenAuthentication = InstallationAccessTokenData
7071
tokenType: INSTALLATION_TOKEN_TYPE;
7172
};
7273

74+
export type OAuthAppAuthentication = OAuthAppAuth.AppAuthentication;
75+
export type GitHubAppUserAuthentication = OAuthAppAuth.GitHubAppUserAuthentication;
76+
export type GitHubAppUserAuthenticationWithExpiration = OAuthAppAuth.GitHubAppUserAuthenticationWithExpiration;
77+
7378
export type Authentication =
7479
| AppAuthentication
7580
| OAuthAppAuthentication
@@ -104,17 +109,6 @@ export type Permissions = {
104109
[name: string]: string;
105110
};
106111

107-
type CommonAuthOptions = {
108-
installationId?: number | string;
109-
repositoryIds?: number[];
110-
permissions?: Permissions;
111-
refresh?: boolean;
112-
// TODO: return type of `auth({ type: "installation", installationId, factory })`
113-
// should be Promise<ReturnType<factory>>
114-
factory?: (options: FactoryOptions) => unknown;
115-
[key: string]: unknown;
116-
};
117-
118112
export type AuthType =
119113
| "app"
120114
| "installation"
@@ -138,12 +132,16 @@ export type InstallationAuthOptions = {
138132
[key: string]: unknown;
139133
};
140134

135+
export type OAuthAppAuthOptions = OAuthAppAuth.AppAuthOptions;
136+
export type OAuthWebFlowAuthOptions = OAuthAppAuth.WebFlowAuthOptions;
137+
export type OAuthDeviceFlowAuthOptions = OAuthAppAuth.GitHubAppDeviceFlowAuthOptions;
138+
141139
export type AuthOptions =
142140
| AppAuthOptions
143141
| OAuthAppAuthOptions
144142
| InstallationAuthOptions
145-
| WebFlowAuthOptions
146-
| GitHubAppDeviceFlowAuthOptions;
143+
| OAuthWebFlowAuthOptions
144+
| OAuthDeviceFlowAuthOptions;
147145

148146
export type WithInstallationId = {
149147
installationId: number;
@@ -152,5 +150,5 @@ export type WithInstallationId = {
152150
export type State = Required<Omit<CommonStrategyOptions, "installationId">> & {
153151
installationId?: number;
154152
} & OAuthStrategyOptions & {
155-
oauthApp: GitHubAuthInterface;
153+
oauthApp: OAuthAppAuth.GitHubAuthInterface;
156154
};

0 commit comments

Comments
 (0)