diff --git a/example/src/index.js b/example/src/index.js index d58830e..7edf409 100644 --- a/example/src/index.js +++ b/example/src/index.js @@ -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) diff --git a/src/index.ts b/src/index.ts index ee6b370..069c93c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) diff --git a/src/interfaces/IAuthingSSOConstructorParams.ts b/src/interfaces/IAuthingSSOConstructorParams.ts index 1530107..027aef2 100644 --- a/src/interfaces/IAuthingSSOConstructorParams.ts +++ b/src/interfaces/IAuthingSSOConstructorParams.ts @@ -62,7 +62,7 @@ export interface IPopUpLoginParams { responseType?: string; nonce?: string; state?: string; - prompt: IPromptType + prompt?: IPromptType } export interface IGetAccessTokenSilentlyParams extends IPopUpLoginParams{} diff --git a/src/lib/AuthzUrlBuilder.ts b/src/lib/AuthzUrlBuilder.ts index d3156d9..4119711 100644 --- a/src/lib/AuthzUrlBuilder.ts +++ b/src/lib/AuthzUrlBuilder.ts @@ -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)