Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make oidcConfig of IAuthConfig type #674

Merged
merged 3 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion generators/ionic/resources/oauth2/cypress/support/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { apiHost } from './config';
import { environment } from '../../src/environments/environment';

const {
oidcConfig: { scopes: scope, audience, client_id },
audience,
oidcConfig: { scopes: scope, client_id },
} = environment;

// Get oauth2 basic data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { AuthActions, AuthService, IAuthAction } from 'ionic-appauth';
import { Subscription } from 'rxjs';
import { environment } from '../../../environments/environment';

const { audience } = environment;

@Component({
selector: 'app-login',
templateUrl: './login.page.html',
Expand All @@ -25,7 +27,7 @@ export class LoginPage implements OnInit, OnDestroy {
}

public async signIn() {
await this.authService.signIn({ audience: environment.oidcConfig.audience });
await this.authService.signIn({ audience });
}

private async onSignInSuccess(action: IAuthAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { AuthActions, AuthService, IAuthAction } from 'ionic-appauth';
import { Subscription } from 'rxjs';
import { environment } from '../../../environments/environment';

const { audience } = environment;

@Component({
selector: 'app-welcome',
templateUrl: 'welcome.page.html',
Expand All @@ -24,7 +26,7 @@ export class WelcomePage implements OnInit, OnDestroy {
}

signIn() {
this.authService.signIn({ audience: environment.oidcConfig.audience })
this.authService.signIn({ audience })
.catch((error) => console.error(`Sign in error: ${error}`));
}

Expand Down
23 changes: 14 additions & 9 deletions generators/ionic/resources/oauth2/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
/* eslint-disable @typescript-eslint/naming-convention */
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
import type { IAuthConfig } from 'ionic-appauth';

export const apiHost = 'http://localhost:8080/';

const oidcConfig: IAuthConfig = {
client_id: 'web_app',
server_host: 'http://localhost:9080/auth/realms/jhipster',
redirect_url: window.location.origin + '/callback',
end_session_redirect_url: window.location.origin + '/logout',
scopes: 'openid profile',
pkce: true,
};

export const environment = {
production: false,
apiUrl: `${apiHost}api`,
oidcConfig: {
client_id: 'web_app',
server_host: 'http://localhost:9080/auth/realms/jhipster',
redirect_url: window.location.origin + '/callback',
end_session_redirect_url: window.location.origin + '/logout',
scopes: 'openid profile',
pkce: true,
audience: 'api://default'
},
oidcConfig,
audience: 'api://default',
mraible marked this conversation as resolved.
Show resolved Hide resolved
scheme: 'dev.localhost.ionic',
};

Expand Down