Skip to content

Commit

Permalink
fix: state is not required
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyiming0803 committed Jul 19, 2023
1 parent be35f72 commit c7d8b86
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 5 additions & 1 deletion example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ app.use(route.get('/logout/callback', ctx => {
ctx.response.redirect(`/index.html`)
}))

app.listen(3001)
// app.use(route.get('/build/umd/index.min.js', ctx => {
// ctx.response.redirect(`${path.join(__dirname + '../../')}/example/views/index.min.js`)
// }))

app.listen(3004)
23 changes: 10 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,20 @@ export class AuthingSSO {
* @msg: 登录方法
* @param {*}
*/
login(
{
login(options: ILoginParams) {
const {
scope,
responseMode,
responseType,
state,
nonce,
prompt,
}: ILoginParams = {
scope: 'openid profile email phone',
responseMode: 'fragment',
responseType: 'id_token token',
state: Math.random().toString(),
nonce: Math.random().toString(),
prompt: undefined,
}
) {
state,
nonce
} = Object.assign({}, {
scope: 'openid profile email phone',
responseMode: 'fragment',
responseType: 'id_token token'
}, options)

let url = this.authzUrlBuilder
.redirectUri(this.redirectUri)
.scope(scope)
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IAuthingSSOConstructorParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface IPopUpLoginParams {
responseType?: string;
nonce?: string;
state?: string;
prompt: IPromptType
prompt?: IPromptType
}

export interface IGetAccessTokenSilentlyParams extends IPopUpLoginParams{}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/AuthzUrlBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export class AuthzUrlBuilder {
urls.searchParams.append('prompt', this._prompt)
}

urls.searchParams.append('state', this._state)
if (this._state) {
urls.searchParams.append('state', this._state)
}

if (this._nonce) {
urls.searchParams.append('nonce', this._nonce)
Expand Down

0 comments on commit c7d8b86

Please sign in to comment.