@authorizerdev/authorizer-js 1.1.6 → 1.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,17 +18,17 @@ All the above versions require `Authorizer` instance to be instantiated and used
18
18
 
19
19
  ```js
20
20
  const authRef = new Authorizer({
21
- authorizerURL: 'https://app.herokuapp.com',
22
- redirectURL: window.location.origin,
23
- });
21
+ authorizerURL: 'https://app.herokuapp.com',
22
+ redirectURL: window.location.origin,
23
+ })
24
24
  ```
25
25
 
26
- ## UMD
26
+ ## IIFE
27
27
 
28
28
  - Step 1: Load Javascript using CDN
29
29
 
30
30
  ```html
31
- <script src="https://unpkg.com/@authorizerdev/authorizer-js/lib/authorizer.min.js"></script>
31
+ <script src="https://unpkg.com/@authorizerdev/authorizer-js/dist/index.global.js"></script>
32
32
  ```
33
33
 
34
34
  - Step 2: Use the library to instantiate `Authorizer` instance and access [various methods](/authorizer-js/functions)
@@ -80,18 +80,18 @@ yarn add @authorizerdev/authoirzer-js
80
80
  - Step 2: Import and initialize the authorizer instance
81
81
 
82
82
  ```js
83
- const { Authorizer } = require('@authorizerdev/authoirzer-js');
83
+ const { Authorizer } = require('@authorizerdev/authoirzer-js')
84
84
 
85
85
  const authRef = new Authorizer({
86
- authorizerURL: 'https://app.heroku.com',
87
- redirectURL: 'http://app.heroku.com/app',
88
- });
86
+ authorizerURL: 'https://app.heroku.com',
87
+ redirectURL: 'http://app.heroku.com/app',
88
+ })
89
89
 
90
90
  async function main() {
91
- await authRef.login({
92
- email: 'foo@bar.com',
93
- password: 'test',
94
- });
91
+ await authRef.login({
92
+ email: 'foo@bar.com',
93
+ password: 'test',
94
+ })
95
95
  }
96
96
  ```
97
97
 
@@ -108,18 +108,18 @@ yarn add @authorizerdev/authorizer-js
108
108
  - Step 2: Import and initialize the authorizer instance
109
109
 
110
110
  ```js
111
- import { Authorizer } from '@authorizerdev/authorizer-js';
111
+ import { Authorizer } from '@authorizerdev/authorizer-js'
112
112
 
113
113
  const authRef = new Authorizer({
114
- authorizerURL: 'https://app.heroku.com',
115
- redirectURL: 'http://app.heroku.com/app',
116
- });
114
+ authorizerURL: 'https://app.heroku.com',
115
+ redirectURL: 'http://app.heroku.com/app',
116
+ })
117
117
 
118
118
  async function main() {
119
- await authRef.login({
120
- email: 'foo@bar.com',
121
- password: 'test',
122
- });
119
+ await authRef.login({
120
+ email: 'foo@bar.com',
121
+ password: 'test',
122
+ })
123
123
  }
124
124
  ```
125
125
 
@@ -1,10 +1,10 @@
1
- export interface ConfigType {
1
+ interface ConfigType {
2
2
  authorizerURL: string;
3
3
  redirectURL: string;
4
4
  clientID: string;
5
5
  extraHeaders?: Record<string, string>;
6
6
  }
7
- export interface User {
7
+ interface User {
8
8
  id: string;
9
9
  email: string;
10
10
  preferred_username: string;
@@ -24,7 +24,7 @@ export interface User {
24
24
  updated_at: number;
25
25
  is_multi_factor_auth_enabled?: boolean;
26
26
  }
27
- export interface AuthToken {
27
+ interface AuthToken {
28
28
  message?: string;
29
29
  access_token: string;
30
30
  expires_in: number;
@@ -33,18 +33,18 @@ export interface AuthToken {
33
33
  user?: User;
34
34
  should_show_otp_screen?: boolean;
35
35
  }
36
- export interface Response {
36
+ interface Response {
37
37
  message: string;
38
38
  }
39
- export type Headers = Record<string, string>;
40
- export interface LoginInput {
39
+ type Headers = Record<string, string>;
40
+ interface LoginInput {
41
41
  email: string;
42
42
  password: string;
43
43
  roles?: string[];
44
44
  scope?: string[];
45
45
  state?: string;
46
46
  }
47
- export interface SignupInput {
47
+ interface SignupInput {
48
48
  email: string;
49
49
  password: string;
50
50
  confirm_password: string;
@@ -62,31 +62,31 @@ export interface SignupInput {
62
62
  is_multi_factor_auth_enabled?: boolean;
63
63
  state?: string;
64
64
  }
65
- export interface MagicLinkLoginInput {
65
+ interface MagicLinkLoginInput {
66
66
  email: string;
67
67
  roles?: string[];
68
68
  scopes?: string[];
69
69
  state?: string;
70
70
  redirect_uri?: string;
71
71
  }
72
- export interface VerifyEmailInput {
72
+ interface VerifyEmailInput {
73
73
  token: string;
74
74
  state?: string;
75
75
  }
76
- export interface VerifyOtpInput {
76
+ interface VerifyOtpInput {
77
77
  email: string;
78
78
  otp: string;
79
79
  state?: string;
80
80
  }
81
- export interface ResendOtpInput {
81
+ interface ResendOtpInput {
82
82
  email: string;
83
83
  }
84
- export interface GraphqlQueryInput {
84
+ interface GraphqlQueryInput {
85
85
  query: string;
86
86
  variables?: Record<string, any>;
87
87
  headers?: Headers;
88
88
  }
89
- export interface MetaData {
89
+ interface MetaData {
90
90
  version: string;
91
91
  client_id: string;
92
92
  is_google_login_enabled: boolean;
@@ -102,7 +102,7 @@ export interface MetaData {
102
102
  is_sign_up_enabled: boolean;
103
103
  is_strong_password_enabled: boolean;
104
104
  }
105
- export interface UpdateProfileInput {
105
+ interface UpdateProfileInput {
106
106
  old_password?: string;
107
107
  new_password?: string;
108
108
  confirm_new_password?: string;
@@ -117,69 +117,99 @@ export interface UpdateProfileInput {
117
117
  picture?: string;
118
118
  is_multi_factor_auth_enabled?: boolean;
119
119
  }
120
- export interface ForgotPasswordInput {
120
+ interface ForgotPasswordInput {
121
121
  email: string;
122
122
  state?: string;
123
123
  redirect_uri?: string;
124
124
  }
125
- export interface ResetPasswordInput {
125
+ interface ResetPasswordInput {
126
126
  token: string;
127
127
  password: string;
128
128
  confirm_password: string;
129
129
  }
130
- export interface SessionQueryInput {
130
+ interface SessionQueryInput {
131
131
  roles?: string[];
132
132
  }
133
- export interface IsValidJWTQueryInput {
133
+ interface IsValidJWTQueryInput {
134
134
  jwt: string;
135
135
  roles?: string[];
136
136
  }
137
- export interface ValidJWTResponse {
137
+ interface ValidJWTResponse {
138
138
  valid: string;
139
139
  message: string;
140
140
  }
141
- export declare enum OAuthProviders {
141
+ declare enum OAuthProviders {
142
142
  Apple = "apple",
143
143
  Github = "github",
144
144
  Google = "google",
145
145
  Facebook = "facebook",
146
146
  LinkedIn = "linkedin"
147
147
  }
148
- export declare enum ResponseTypes {
148
+ declare enum ResponseTypes {
149
149
  Code = "code",
150
150
  Token = "token"
151
151
  }
152
- export interface AuthorizeInput {
152
+ interface AuthorizeInput {
153
153
  response_type: ResponseTypes;
154
154
  use_refresh_token?: boolean;
155
155
  response_mode?: string;
156
156
  }
157
- export interface AuthorizeResponse {
157
+ interface AuthorizeResponse {
158
158
  state: string;
159
159
  code?: string;
160
160
  error?: string;
161
161
  error_description?: string;
162
162
  }
163
- export interface RevokeTokenInput {
163
+ interface RevokeTokenInput {
164
164
  refresh_token: string;
165
165
  }
166
- export interface GetTokenInput {
166
+ interface GetTokenInput {
167
167
  code?: string;
168
168
  grant_type?: string;
169
169
  refresh_token?: string;
170
170
  }
171
- export interface GetTokenResponse {
171
+ interface GetTokenResponse {
172
172
  access_token: string;
173
173
  expires_in: number;
174
174
  id_token: string;
175
175
  refresh_token?: string;
176
176
  }
177
- export interface ValidateJWTTokenInput {
177
+ interface ValidateJWTTokenInput {
178
178
  token_type: 'access_token' | 'id_token' | 'refresh_token';
179
179
  token: string;
180
180
  roles?: string[];
181
181
  }
182
- export interface ValidateJWTTokenResponse {
182
+ interface ValidateJWTTokenResponse {
183
183
  is_valid: boolean;
184
184
  claims: Record<string, any>;
185
185
  }
186
+
187
+ declare class Authorizer {
188
+ config: ConfigType;
189
+ codeVerifier: string;
190
+ constructor(config: ConfigType);
191
+ authorize: (data: AuthorizeInput) => Promise<GetTokenResponse | AuthorizeResponse | undefined>;
192
+ browserLogin: () => Promise<AuthToken | void>;
193
+ forgotPassword: (data: ForgotPasswordInput) => Promise<Response | void>;
194
+ getMetaData: () => Promise<MetaData | void>;
195
+ getProfile: (headers?: Headers) => Promise<User | void>;
196
+ getSession: (headers?: Headers, params?: SessionQueryInput) => Promise<AuthToken>;
197
+ getToken: (data: GetTokenInput) => Promise<GetTokenResponse>;
198
+ graphqlQuery: (data: GraphqlQueryInput) => Promise<any>;
199
+ login: (data: LoginInput) => Promise<AuthToken | void>;
200
+ logout: (headers?: Headers) => Promise<Response | void>;
201
+ magicLinkLogin: (data: MagicLinkLoginInput) => Promise<Response>;
202
+ oauthLogin: (oauthProvider: string, roles?: string[], redirect_uri?: string, state?: string) => Promise<void>;
203
+ resendOtp: (data: ResendOtpInput) => Promise<Response | void>;
204
+ resetPassword: (data: ResetPasswordInput) => Promise<Response | void>;
205
+ revokeToken: (data: {
206
+ refresh_token: string;
207
+ }) => Promise<any>;
208
+ signup: (data: SignupInput) => Promise<AuthToken | void>;
209
+ updateProfile: (data: UpdateProfileInput, headers?: Headers) => Promise<Response | void>;
210
+ validateJWTToken: (params?: ValidateJWTTokenInput) => Promise<ValidateJWTTokenResponse>;
211
+ verifyEmail: (data: VerifyEmailInput) => Promise<AuthToken | void>;
212
+ verifyOtp: (data: VerifyOtpInput) => Promise<AuthToken | void>;
213
+ }
214
+
215
+ export { AuthToken, AuthorizeInput, AuthorizeResponse, Authorizer, ConfigType, ForgotPasswordInput, GetTokenInput, GetTokenResponse, GraphqlQueryInput, Headers, IsValidJWTQueryInput, LoginInput, MagicLinkLoginInput, MetaData, OAuthProviders, ResendOtpInput, ResetPasswordInput, Response, ResponseTypes, RevokeTokenInput, SessionQueryInput, SignupInput, UpdateProfileInput, User, ValidJWTResponse, ValidateJWTTokenInput, ValidateJWTTokenResponse, VerifyEmailInput, VerifyOtpInput };