-
Notifications
You must be signed in to change notification settings - Fork 2
/
interface.ts
135 lines (122 loc) · 5.55 KB
/
interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { ApiBasedLoginData } from './docs/api-based-interface';
import { ClientSideLoginData } from './docs/client-side-interface';
/**
* After coordinating your Custom SSO integration with Second Street,
* we will suggest either an API-based workflow or a client-side workflow.
* Based on which workflow you are using, the LoginData you'll need to provide
* will change. Provide ApiBasedLoginData for the API-based workflow, or provide
* ClientSideLoginData for the client-side workflow.
*/
export type LoginData = ApiBasedLoginData | ClientSideLoginData;
export enum ThirdParty {
// Your ThirdParty ID will be provided by Second Street.
}
export interface LogoutData {
thirdPartyId: ThirdParty;
}
export enum LoginStrategy {
/*
* If your login system does not expose a way for users to log into and out of
* your website, choose NoLoginUI. In this case, when a visitor to the page
* upon which the promotion is embedded is not logged into your website, the
* promotion will ask them for their email address and other fields that you
* configured on the promotion's form. If the user is logged into your
* website, we'll skip the fields that your custom SSO implementation has
* already sent to Second Street.
*/
NoLoginUI = 0,
/*
* If your login system exposes a way for users to log into and out of your
* website, choose MyLoginUI. In this case, when a visitor to the page upon
* which the promotion is embedded is not logged into your website, the
* promotion will not allow the user to proceed with registration and/or entry
* until they have logged into your website's authentication system. If the
* user is logged into your website, we'll skip the fields that your custom
* SSO implementation has already sent to Second Street.
*/
MyLoginUI = 1
}
/**
* Implement this interface if using LoginStrategy.NoLoginUI.
*/
export interface CustomSSOWithoutLoginUI {
/**
* Second Street will inform you what your ThirdParty ID is.
*/
id: ThirdParty;
/**
* purpose: A configuration setting that will change the behavior of embedded
* promotions. If it is not set, LoginStrategy.MyLoginUI is assumed.
*
* context: See LoginStrategy.
*/
loginStrategy: LoginStrategy.NoLoginUI;
/**
* purpose: A method that, when called, informs Second Street if the user
* is currently logged into your authentication system. If the user
* is logged in, it should return their data. If the user is
* not logged in, it should return null. For logged in users, the type
* of data you should return is based on the workflow you're using.
*
* context: Second Street will call this method when its embed code starts
* up, so that it can know the initial user login state before
* attaching event handlers. Second Street may call this method
* one or more times.
*/
isLoggedIn(): LoginData | null;
/**
* purpose: A method that, when called, registers a function to be called
* when the user logs into your authentication system. The function
* should provide the data of the user logging in as an argument, and
* the type of data to return is based on the workflow you're using.
*
* context: Second Street will call this method when its embed code starts
* up, so that it can log the user into the embedded content when
* they log into your site. Second Street may attach one or more
* handlers.
*/
addLoginHandler(fn: (data: LoginData) => void): void;
/**
* purpose: A method that, when called, registers a function to be called
* when the user logs out of your authentication system.
*
* context: Second Street will call this method when its embed code starts
* up, so that it can log the user out of the embedded content when
* they log out of your site. Second Street may attach one or more
* handlers.
*/
addLogoutHandler(fn: (data: LogoutData) => void): void;
}
/**
* Implement this interface if using LoginStrategy.MyLoginUI.
*/
export interface CustomSSOWithMyLoginUI extends Omit<CustomSSOWithoutLoginUI, 'loginStrategy'> {
/**
* purpose: A configuration setting that will change the behavior of embedded
* promotions. If it is not set, LoginStrategy.MyLoginUI is assumed.
*
* context: See LoginStrategy.
*/
loginStrategy?: LoginStrategy.MyLoginUI;
/**
* purpose: A method that, when called, shows your website's login UI. If the
* login UI was successfully shown (or was successfully queued to be
* shown), it should return true. Otherwise, it should return false.
*
* context: Second Street will call this method when the user tries to take
* an action that requires the user to be authenticated. Second
* Street may call this method one or more times.
*/
requestLogin(): boolean;
/**
* purpose: A method that, when called, registers a function to be called
* when your website's login UI (the same one requestLogin() shows)
* is aborted by the user without logging into your website.
*
* context: Second Street will call this method when its embed code starts
* up, so that it is aware when the user chooses not to log in.
* Second Street may attach one or more handlers.
*/
addLoginCanceledHandler(fn: (data: LogoutData) => void): void;
}
export type SecondStreetThirdPartyAuth<T> = T extends LoginStrategy.NoLoginUI ? CustomSSOWithoutLoginUI : CustomSSOWithMyLoginUI;