Skip to content

Commit 9ffb7ef

Browse files
author
周雅风
committed
feat(auth): 🎨 params login_hint
1 parent 5dd4c9b commit 9ffb7ef

File tree

3 files changed

+72
-35
lines changed

3 files changed

+72
-35
lines changed

src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ export class AuthingSSO {
9595
scope: "openid profile email phone",
9696
responseMode: "fragment",
9797
responseType: "id_token token",
98+
<<<<<<< Updated upstream
9899
nonce: Math.random().toString(),
100+
=======
101+
>>>>>>> Stashed changes
99102
},
100103
options
101104
);
@@ -124,6 +127,7 @@ export class AuthingSSO {
124127
* @param {*}
125128
*/
126129
login(options: ILoginParams) {
130+
<<<<<<< Updated upstream
127131
const { scope, responseMode, responseType, prompt, state, nonce } =
128132
Object.assign(
129133
{},
@@ -135,6 +139,25 @@ export class AuthingSSO {
135139
},
136140
options
137141
);
142+
=======
143+
const {
144+
scope,
145+
responseMode,
146+
responseType,
147+
prompt,
148+
state,
149+
nonce,
150+
login_hint,
151+
} = Object.assign(
152+
{},
153+
{
154+
scope: "openid profile email phone",
155+
responseMode: "fragment",
156+
responseType: "id_token token",
157+
},
158+
options
159+
);
160+
>>>>>>> Stashed changes
138161

139162
let url = this.authzUrlBuilder
140163
.redirectUri(this.redirectUri)
@@ -145,6 +168,10 @@ export class AuthingSSO {
145168
.prompt(prompt)
146169
.state(state)
147170
.nonce(nonce)
171+
<<<<<<< Updated upstream
172+
=======
173+
.loginHint(login_hint)
174+
>>>>>>> Stashed changes
148175
.build();
149176

150177
if (isInElectron) {

src/interfaces/IAuthingSSOConstructorParams.ts

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,44 @@ export interface IAuthingSSOConstructorParams {
55
}
66

77
export interface PopUpLoginSuccessParams {
8-
access_token: string,
9-
id_token: string
8+
access_token: string;
9+
id_token: string;
1010
}
1111

1212
export interface PopUpLoginFailParams {
13-
error: string,
14-
error_description: string
13+
error: string;
14+
error_description: string;
1515
}
1616

1717
export interface DataParams {
18-
code: number,
19-
data: any,
20-
message: string
18+
code: number;
19+
data: any;
20+
message: string;
2121
}
2222

2323
export interface GetTokenParams {
24-
error?: string,
25-
error_description?: string,
26-
phone_number?: string,
27-
phone_number_verified?: boolean,
28-
sub?: string,
29-
email?: string,
30-
email_verified?: boolean,
31-
birthdate?: string,
32-
family_name?: string,
33-
gender?: string,
34-
given_name?: string,
35-
locale?: string,
36-
middle_name?: string,
37-
name?: string,
38-
nickname?: string,
39-
picture?: string,
40-
preferred_username?: string,
41-
profile?: string,
42-
updated_at?: string,
43-
website?: string,
44-
zoneinfo?: string,
45-
[proppName:string]: any;
24+
error?: string;
25+
error_description?: string;
26+
phone_number?: string;
27+
phone_number_verified?: boolean;
28+
sub?: string;
29+
email?: string;
30+
email_verified?: boolean;
31+
birthdate?: string;
32+
family_name?: string;
33+
gender?: string;
34+
given_name?: string;
35+
locale?: string;
36+
middle_name?: string;
37+
name?: string;
38+
nickname?: string;
39+
picture?: string;
40+
preferred_username?: string;
41+
profile?: string;
42+
updated_at?: string;
43+
website?: string;
44+
zoneinfo?: string;
45+
[proppName: string]: any;
4646
}
4747

4848
export interface emptyObjParams {
@@ -53,18 +53,20 @@ export interface emptyObjParams {
5353
}
5454

5555
// 定义交互方式:
56-
export type IPromptType = 'none' // 永远不提示用户做任何登录,无需输密码
57-
| 'consent' // 每次用户认证完后都要进行二次确认
58-
| 'login' // 默认值
56+
export type IPromptType =
57+
| "none" // 永远不提示用户做任何登录,无需输密码
58+
| "consent" // 每次用户认证完后都要进行二次确认
59+
| "login"; // 默认值
5960
export interface IPopUpLoginParams {
6061
scope?: string;
6162
responseMode?: string;
6263
responseType?: string;
6364
nonce?: string;
6465
state?: string;
65-
prompt?: IPromptType
66+
prompt?: IPromptType;
67+
login_hint?: string;
6668
}
6769

68-
export interface IGetAccessTokenSilentlyParams extends IPopUpLoginParams{}
70+
export interface IGetAccessTokenSilentlyParams extends IPopUpLoginParams {}
6971

70-
export interface ILoginParams extends IPopUpLoginParams{}
72+
export interface ILoginParams extends IPopUpLoginParams {}

src/lib/AuthzUrlBuilder.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class AuthzUrlBuilder {
99
private _prompt: string | undefined;
1010
private _state: string = Math.random().toString();
1111
private _nonce: string;
12+
private _loginHint: string;
1213
private _scope: string = "openid email phone profile offline_access";
1314
private _loginPageContext: string;
1415

@@ -53,6 +54,9 @@ export class AuthzUrlBuilder {
5354
urls.searchParams.append("nonce", this._nonce);
5455
}
5556

57+
if (this._loginHint) {
58+
urls.searchParams.append("login_hint", this._loginHint);
59+
}
5660
return urls;
5761
}
5862

@@ -111,6 +115,10 @@ export class AuthzUrlBuilder {
111115
this._nonce = rand;
112116
return this;
113117
}
118+
loginHint(loginHint: string) {
119+
this._loginHint = loginHint;
120+
return this;
121+
}
114122
loginPageContext(context: string) {
115123
this._loginPageContext = context;
116124
return this;

0 commit comments

Comments
 (0)