Skip to content

Commit 4abd628

Browse files
custom login config docs updated and cognito example docs updated
1 parent db92e15 commit 4abd628

File tree

4 files changed

+315
-172
lines changed

4 files changed

+315
-172
lines changed

docs/open-login/api-reference/initialization.mdx

+255-4
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,22 @@ The OpenLogin constructor takes an object with `OpenLoginOptions` as input.
2727

2828
- `options` - `OpenLoginOptions`: The options of the constructor
2929
- `clientId` - `string` : Your project id which you can get from [developer dashboard](https://developer.tor.us/)
30+
3031
- `network` - `enum`: Environment to run openlogin (testnet, mainnet, development)
32+
3133
- `_iframeUrl`- `string`: Url of openlogin iframe, you can pass custom iframe url here else
3234
it will be added based on network value.For testnet iframe url is `https://beta.openlogin.com` and
3335
for mainnet it is `https://app.openlogin.com`. If you are passing valid `network` value then network value
3436
will be given precedence over iframe url.
3537

3638
- `uxMode` - `enum`(optional): `popup` and `redirect` uxmode are supported. By default it is set to `redirect`
3739

40+
- `loginConfig` -`LoginConfig`(optional): LoginConfig allows you to specify custom loginConfig to customize visiblity of login modal
41+
options and to specify your custom verifier for each login option.
42+
43+
- `whiteLabel`: `WhiteLabelData` (optional): Options for whitelabling default openlogin modal.
44+
You can toggle theme and primary colors of login modal and openlogin verification screens by using WhiteLabelData.
45+
3846
**Returns**
3947

4048
- `Object`: The openlogin instance with all its methods and events.
@@ -43,16 +51,147 @@ The OpenLogin constructor takes an object with `OpenLoginOptions` as input.
4351

4452
```javascript
4553
type OpenLoginOptions = {
54+
/**
55+
* You can get your clientId/projectId by registering your
56+
* dapp on {@link "https://developer.tor.us"| developer dashbaord}
57+
*/
4658
clientId: string;
59+
60+
/**
61+
* network specifies the openlogin iframe url url to be used.
62+
*
63+
* - `'mainnet'`: https://app.openlogin.com will be used which is the production version.
64+
* - `'testnet'`: https://beta.openlogin.com will be used which is the beta version.
65+
* - `'development'`: http://localhost:3000 will be used for development purpose.
66+
*/
4767
network: OPENLOGIN_NETWORK_TYPE;
48-
_iframeUrl?: string;
68+
69+
/**
70+
* Setting no3PC forces openlogin to assume that third party cookies are blocked
71+
* in the browser.
72+
*
73+
* @defaultValue false
74+
* @remarks
75+
* Only pass no3PC to `true` when you are sure that third party cookies are not
76+
* supported. By default openlogin will self check third party cookies and proceed
77+
* accordingly.
78+
*/
79+
no3PC?: boolean;
80+
81+
/**
82+
* redirectUrl is the dapp's url where user will be redirected after login.
83+
*
84+
* @remarks
85+
* Register this url at {@link "https://developer.tor.us"| developer dashbaord}
86+
* else initialization will give error.
87+
*/
4988
redirectUrl?: string;
50-
loginUrl?: string;
51-
webAuthnUrl?: string;
52-
logoutUrl?: string;
89+
90+
/**
91+
* two uxModes are supported:-
92+
* - `'POPUP'`: In this uxMode, a popup will be shown to user for login.
93+
* - `'REDIRECT'`: In this uxMode, user will be redirected to a new window tab for login.
94+
*
95+
* @defaultValue `'POPUP'`
96+
* @remarks
97+
*
98+
* Use of `'REDIRECT'` mode is recommended in browsers where popups might get blocked.
99+
*/
53100
uxMode?: UX_MODE_TYPE;
101+
102+
/**
103+
* replaceUrlOnRedirect removes the params from the redirected url after login
104+
*
105+
* @defaultValue true
106+
*/
54107
replaceUrlOnRedirect?: boolean;
108+
109+
/**
110+
* originData is used to verify the origin of dapp by iframe.
111+
*
112+
* @internal
113+
* @remarks
114+
* You don't have to pass originData explicitly if you have registered your dapp at
115+
* {@link "https://developer.tor.us"| developer dashbaord}.
116+
*
117+
* originData contains a signature of dapp's origin url which is generated using
118+
* project's secret.
119+
*/
55120
originData?: OriginData;
121+
122+
/**
123+
* loginConfig enables you to pass your own login verifiers configuration for various
124+
* loginProviders.
125+
*
126+
* loginConfig is key value map where each key should be a valid loginProvider and value
127+
* should be custom configuration for that loginProvider
128+
*
129+
* @remarks
130+
* You can deploy your own verifiers from {@link "https://developer.tor.us"| developer dashbaord}
131+
* to use here.
132+
*
133+
*/
134+
loginConfig?: LoginConfig;
135+
136+
/**
137+
* _iframeUrl is for internal development use only and is used to override the
138+
* `network` parameter.
139+
* @internal
140+
*/
141+
_iframeUrl?: string;
142+
/**
143+
* _startUrl is for internal development use only and is used specify authentication
144+
* start url of iframe.
145+
* @internal
146+
*/
147+
_startUrl?: string;
148+
149+
/**
150+
* _popupUrl is for internal development use only and is used specify url of popup window
151+
* for popup uxMode.
152+
* @internal
153+
*/
154+
_popupUrl?: string;
155+
156+
/**
157+
* options for whitelabling default openlogin modal.
158+
*/
159+
whiteLabel?: WhiteLabelData;
160+
};
161+
162+
type WhiteLabelData = {
163+
/**
164+
* App name to display in the UI
165+
*/
166+
name?: string;
167+
/**
168+
* App logo to use in light mode
169+
*/
170+
logoLight?: string;
171+
/**
172+
* App logo to use in dark mode
173+
*/
174+
logoDark?: string;
175+
/**
176+
* Default language to use
177+
*
178+
* @defaultValue en
179+
*/
180+
defaultLanguage?: string;
181+
/**
182+
* Whether to enable dark mode
183+
*
184+
* @defaultValue false
185+
*/
186+
dark?: boolean;
187+
188+
/**
189+
* Used to customize theme of the login modal with following options
190+
* `'primary'` - To customize primary color of modal's content.
191+
*/
192+
theme?: {
193+
[P in string]: string;
194+
};
56195
};
57196

58197
const OPENLOGIN_NETWORK = {
@@ -85,6 +224,118 @@ const openlogin = new OpenLogin({
85224
});
86225
```
87226

227+
## Using Custom login configuration
228+
229+
230+
By default , openlogin will use verifiers deployed by torus and will show all default available login options in login modal.
231+
If you want to customize the login modal or want to use your own login verifiers then you can use custom login configuration
232+
with openlogin.
233+
234+
For ex: In code snippet below, we are customizing loginConfig to show only google and facebook as login options in default
235+
openlogin modal. Also you can pass your own verifiers in the configuration for any of the login providers.
236+
237+
```javascript
238+
const openlogin = new OpenLogin({
239+
// your clientId aka projectId , get it from https://developer.tor.us
240+
// clientId is not required for localhost, you can set it to any string
241+
// for development
242+
clientId: YOUR_PROJECT_ID,
243+
network: "testnet",
244+
// you can pass login config to modify default
245+
// login options in login modal, also you can pass
246+
// your own verifiers.
247+
loginConfig: {
248+
google: {
249+
verifier: "tkey-google-lrc",
250+
name: "google",
251+
typeOfLogin: "google",
252+
showOnModal: true,
253+
showOnDesktop: true,
254+
showOnMobile: true,
255+
},
256+
facebook: {
257+
verifier: "tkey-facebook-lrc",
258+
name: "facebook",
259+
typeOfLogin: "facebook",
260+
showOnModal: true,
261+
showOnDesktop: false,
262+
showOnMobile: true,
263+
mainOption: true,
264+
description: "facebook social login",
265+
},
266+
},
267+
});
268+
```
269+
270+
**Reference**
271+
```javascript
272+
273+
type LoginConfig = Record<
274+
string,
275+
{
276+
verifier: string;
277+
278+
/**
279+
* The type of login. Refer to enum `LOGIN_TYPE`
280+
*/
281+
typeOfLogin: TypeOfLogin;
282+
283+
/**
284+
* Display Name. If not provided, we use the default for openlogin app
285+
*/
286+
name: string;
287+
288+
/**
289+
* Description for button. If provided, it renders as a full length button. else, icon button
290+
*/
291+
description?: string;
292+
293+
/**
294+
* Custom client_id. If not provided, we use the default for openlogin app
295+
*/
296+
clientId?: string;
297+
298+
verifierSubIdentifier?: string;
299+
300+
/**
301+
* Logo to be shown on mouse hover. If not provided, we use the default for openlogin app
302+
*/
303+
logoHover?: string;
304+
305+
/**
306+
* Logo to be shown on dark background (dark theme). If not provided, we use the default for openlogin app
307+
*/
308+
logoLight?: string;
309+
310+
/**
311+
* Logo to be shown on light background (light theme). If not provided, we use the default for openlogin app
312+
*/
313+
logoDark?: string;
314+
315+
/**
316+
* Show login button on the main list
317+
*/
318+
mainOption?: boolean;
319+
320+
/**
321+
* Whether to show the login button on modal or not
322+
*/
323+
showOnModal?: boolean;
324+
325+
/**
326+
* Whether to show the login button on desktop
327+
*/
328+
showOnDesktop?: boolean;
329+
330+
/**
331+
* Whether to show the login button on mobile
332+
*/
333+
showOnMobile?: boolean;
334+
}
335+
>;
336+
337+
```
338+
88339
## `init`
89340

90341
Initialize the OpenLogin object after creation. Init sync up the state of user login session in

docs/open-login/api-reference/usage.mdx

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ await openlogin.login(params);
1616

1717
- `params` - `LoginParams` \(optional\) : The login options. Used to specify a
1818
type of login.
19+
1920
- `loginProvider` - `LOGIN_PROVIDER` : The loginProvider name. Supported loginProviders are can be of any value given in
2021
LOGIN_PROVIDER. In future versions you can pass custom loginProvider apart from options given LOGIN_PROVIDER.
2122

@@ -190,11 +191,11 @@ const privKey = await openlogin.login();
190191

191192
```javascript
192193
const privKey = await openlogin.login({
193-
extraLoginOptions: {
194-
login_hint: email,
195-
},
196-
loginProvider: "email_passwordless",
197-
redirectUrl: `https://example.com/redirect`,
194+
extraLoginOptions: {
195+
login_hint: email,
196+
},
197+
loginProvider: "email_passwordless",
198+
redirectUrl: `https://example.com/redirect`,
198199
});
199200
```
200201

0 commit comments

Comments
 (0)