@backstage/core-app-api 1.9.1 → 1.10.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @backstage/core-app-api
2
2
 
3
+ ## 1.10.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 18619f793c94: Fixed two bugs in how the `OAuth2Session` type represents the underlying data. The `expiresAt` and `backstageIdentity` are now both optional, since that's what they are in practice. This is not considered a breaking change since it was effectively a bug in the modelling of the state that this type represents, and the type was not used in any other external contract.
8
+ - 18619f793c94: The `OAuth` class which is used by all OAuth providers will now consider both the session expiration of both the Backstage identity as well as the upstream identity provider, and refresh the session with either of them is about to expire.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+ - @backstage/core-plugin-api@1.6.0-next.0
14
+ - @backstage/config@1.0.8
15
+ - @backstage/types@1.1.0
16
+ - @backstage/version-bridge@1.0.4
17
+
3
18
  ## 1.9.1
4
19
 
5
20
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReactNode, PropsWithChildren, ComponentType } from 'react';
1
+ import React, { ReactNode, PropsWithChildren, ComponentType } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
4
4
  import { ApiHolder, ApiRef, ApiFactory, AnyApiRef, OAuthRequestApi, DiscoveryApi, AuthProviderInfo, ConfigApi, githubAuthApiRef, gitlabAuthApiRef, googleAuthApiRef, OAuthApi, OpenIdConnectApi, ProfileInfoApi, BackstageIdentityApi, SessionApi, SessionState, AuthRequestOptions, BackstageIdentityResponse, ProfileInfo, oktaAuthApiRef, microsoftAuthApiRef, oneloginAuthApiRef, bitbucketAuthApiRef, bitbucketServerAuthApiRef, atlassianAuthApiRef, AlertApi, AlertMessage, AnalyticsApi, AnalyticsEvent, AppThemeApi, AppTheme, ErrorApi, ErrorApiError, ErrorApiErrorContext, FeatureFlagsApi, FeatureFlag, FeatureFlagsSaveOptions, FetchApi, IdentityApi, OAuthRequesterOptions, OAuthRequester, PendingOAuthRequest, StorageApi, StorageValueSnapshot, BackstagePlugin, IconComponent, ExternalRouteRef, AnyApiFactory, RouteRef, SubRouteRef } from '@backstage/core-plugin-api';
@@ -22,7 +22,7 @@ type ApiProviderProps = {
22
22
  * @public
23
23
  */
24
24
  declare const ApiProvider: {
25
- (props: PropsWithChildren<ApiProviderProps>): JSX.Element;
25
+ (props: PropsWithChildren<ApiProviderProps>): React.JSX.Element;
26
26
  propTypes: {
27
27
  apis: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
28
28
  get: PropTypes.Validator<(...args: any[]) => any>;
@@ -192,10 +192,10 @@ type OAuth2Session = {
192
192
  idToken: string;
193
193
  accessToken: string;
194
194
  scopes: Set<string>;
195
- expiresAt: Date;
195
+ expiresAt?: Date;
196
196
  };
197
197
  profile: ProfileInfo;
198
- backstageIdentity: BackstageIdentityResponse;
198
+ backstageIdentity?: BackstageIdentityResponse;
199
199
  };
200
200
 
201
201
  /**
@@ -671,7 +671,7 @@ interface AppRouterProps {
671
671
  * the sign-in page. Once the user has signed-in, it will instead render
672
672
  * the app, while providing routing and route tracking for the app.
673
673
  */
674
- declare function AppRouter(props: AppRouterProps): JSX.Element;
674
+ declare function AppRouter(props: AppRouterProps): React.JSX.Element;
675
675
 
676
676
  /**
677
677
  * Props for the `BootErrorPage` component of {@link AppComponents}.
@@ -1048,6 +1048,6 @@ type FeatureFlaggedProps = {
1048
1048
  *
1049
1049
  * @public
1050
1050
  */
1051
- declare const FeatureFlagged: (props: FeatureFlaggedProps) => JSX.Element;
1051
+ declare const FeatureFlagged: (props: FeatureFlaggedProps) => React.JSX.Element;
1052
1052
 
1053
1053
  export { AlertApiForwarder, ApiFactoryHolder, ApiFactoryRegistry, ApiFactoryScope, ApiProvider, ApiProviderProps, ApiResolver, AppComponents, AppConfigLoader, AppContext, AppIcons, AppOptions, AppRouteBinder, AppRouter, AppRouterProps, AppThemeSelector, AtlassianAuth, AuthApiCreateOptions, BackstageApp, BitbucketAuth, BitbucketServerAuth, BitbucketServerSession, BitbucketSession, BootErrorPageProps, ErrorAlerter, ErrorApiForwarder, ErrorBoundaryFallbackProps, FeatureFlagged, FeatureFlaggedProps, FetchMiddleware, FetchMiddlewares, FlatRoutes, FlatRoutesProps, FrontendHostDiscovery, GithubAuth, GitlabAuth, GoogleAuth, LocalStorageFeatureFlags, MicrosoftAuth, MultipleAnalyticsApi, NoOpAnalyticsApi, OAuth2, OAuth2CreateOptions, OAuth2Session, OAuthApiCreateOptions, OAuthRequestManager, OktaAuth, OneLoginAuth, OneLoginAuthCreateOptions, PopupOptions, SamlAuth, SignInPageProps, UnhandledErrorForwarder, UrlPatternDiscovery, WebStorage, createFetchApi, createSpecializedApp, defaultConfigLoader };
package/dist/index.esm.js CHANGED
@@ -933,8 +933,12 @@ class OAuth2 {
933
933
  environment,
934
934
  provider,
935
935
  oauthRequestApi,
936
- sessionTransform(res) {
937
- return {
936
+ sessionTransform({
937
+ backstageIdentity,
938
+ ...res
939
+ }) {
940
+ var _a;
941
+ const session = {
938
942
  ...res,
939
943
  providerInfo: {
940
944
  idToken: res.providerInfo.idToken,
@@ -943,11 +947,18 @@ class OAuth2 {
943
947
  scopeTransform,
944
948
  res.providerInfo.scope
945
949
  ),
946
- expiresAt: new Date(
947
- Date.now() + res.providerInfo.expiresInSeconds * 1e3
948
- )
950
+ expiresAt: res.providerInfo.expiresInSeconds ? new Date(Date.now() + res.providerInfo.expiresInSeconds * 1e3) : void 0
949
951
  }
950
952
  };
953
+ if (backstageIdentity) {
954
+ const expInSec = (_a = backstageIdentity.expiresInSeconds) != null ? _a : res.providerInfo.expiresInSeconds;
955
+ session.backstageIdentity = {
956
+ token: backstageIdentity.token,
957
+ identity: backstageIdentity.identity,
958
+ expiresAt: expInSec ? new Date(Date.now() + expInSec * 1e3) : void 0
959
+ };
960
+ }
961
+ return session;
951
962
  },
952
963
  popupOptions
953
964
  });
@@ -956,8 +967,21 @@ class OAuth2 {
956
967
  defaultScopes: new Set(defaultScopes),
957
968
  sessionScopes: (session) => session.providerInfo.scopes,
958
969
  sessionShouldRefresh: (session) => {
959
- const expiresInSec = (session.providerInfo.expiresAt.getTime() - Date.now()) / 1e3;
960
- return expiresInSec < 60 * 5;
970
+ var _a, _b;
971
+ let min = Infinity;
972
+ if ((_a = session.providerInfo) == null ? void 0 : _a.expiresAt) {
973
+ min = Math.min(
974
+ min,
975
+ (session.providerInfo.expiresAt.getTime() - Date.now()) / 1e3
976
+ );
977
+ }
978
+ if ((_b = session.backstageIdentity) == null ? void 0 : _b.expiresAt) {
979
+ min = Math.min(
980
+ min,
981
+ (session.backstageIdentity.expiresAt.getTime() - Date.now()) / 1e3
982
+ );
983
+ }
984
+ return min < 60 * 5;
961
985
  }
962
986
  });
963
987
  return new OAuth2({ sessionManager, scopeTransform });