Skip to content

Commit 8792f0e

Browse files
authored
Merge branch 'main' into aromanovv/COMMS-1502-add-label-to-global-search
2 parents 3ddf5fb + 5f6ca51 commit 8792f0e

3 files changed

Lines changed: 84 additions & 75 deletions

File tree

src/app/authorize/components/form-authorize/form-authorize.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,7 @@ mat-card-content.authorize-content {
145145
color: #fff;
146146
background: #085c77;
147147
}
148+
149+
.authorize-button:disabled {
150+
opacity: 0.3;
151+
}

src/app/authorize/components/form-authorize/form-authorize.component.ts

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -190,90 +190,88 @@ export class FormAuthorizeComponent implements OnInit, OnDestroy {
190190
const signinUrl = queryParams ? `/signin?${queryParams}` : '/signin'
191191
;(this.window as any).outOfRouterNavigation(signinUrl)
192192
}
193-
193+
194194
authorize(value = true) {
195-
this.loadingAuthorizeEndpoint = true
195+
this.loadingAuthorizeEndpoint = true;
196196

197197
this._togglz
198198
.getStateOf(TogglzFlag.OAUTH_AUTHORIZATION)
199199
.pipe(
200200
take(1),
201201
tap((useAuthServerFlag) => {
202+
// 1. New logic: Update journey context right away
202203
this._observability.updateJourneyContext('oauth_authorization', {
203204
OAUTH_AUTHORIZATION: useAuthServerFlag,
204-
})
205+
});
206+
}),
207+
switchMap((useAuthServerFlag) => {
205208
if (useAuthServerFlag === true) {
206-
this._oauth
207-
.authorizeOnAuthServer(this.oauthRequest, value)
208-
.pipe(
209-
tap(() => {
210-
this._observability.recordEvent(
211-
'oauth_authorization',
212-
value
213-
? AppEventName.OauthAuthorizationSuccess
214-
: AppEventName.OauthAuthorizationDenied,
215-
{
216-
OAUTH_AUTHORIZATION: true,
217-
}
218-
)
219-
}),
220-
catchError((error) => {
221-
this._observability.recordEvent(
222-
'oauth_authorization',
223-
AppEventName.OauthAuthorizationError,
224-
oauthAuthorizeHttpFailureEventAttrs(
225-
error,
226-
'auth_server',
227-
value,
228-
true
229-
)
209+
return this._oauth.authorizeOnAuthServer(this.oauthRequest, value).pipe(
210+
// 2. Auth Server Telemetry
211+
tap(() => {
212+
this._observability.recordEvent(
213+
'oauth_authorization',
214+
value
215+
? AppEventName.OauthAuthorizationSuccess
216+
: AppEventName.OauthAuthorizationDenied,
217+
{ OAUTH_AUTHORIZATION: true }
218+
);
219+
}),
220+
catchError((error) => {
221+
this._observability.recordEvent(
222+
'oauth_authorization',
223+
AppEventName.OauthAuthorizationError,
224+
oauthAuthorizeHttpFailureEventAttrs(
225+
error,
226+
'auth_server',
227+
value,
228+
true
230229
)
231-
return throwError(() => error)
232-
}),
233-
take(1),
234-
finalize(() => (this.loadingAuthorizeEndpoint = false))
235-
)
236-
.subscribe((redirectUrl) => {
237-
this.redirectUrl.next(redirectUrl)
230+
);
231+
// Throw the error down to the final subscribe block
232+
return throwError(() => error);
238233
})
234+
);
239235
} else {
240-
this._oauth
241-
.authorize(value)
242-
.pipe(
243-
tap(() => {
244-
this._observability.recordEvent(
245-
'oauth_authorization',
246-
value
247-
? AppEventName.OauthAuthorizationSuccess
248-
: AppEventName.OauthAuthorizationDenied,
249-
{
250-
OAUTH_AUTHORIZATION: false,
251-
}
236+
return this._oauth.authorize(value).pipe(
237+
// 3. Legacy Telemetry
238+
tap(() => {
239+
this._observability.recordEvent(
240+
'oauth_authorization',
241+
value
242+
? AppEventName.OauthAuthorizationSuccess
243+
: AppEventName.OauthAuthorizationDenied,
244+
{ OAUTH_AUTHORIZATION: false }
245+
);
246+
}),
247+
catchError((error) => {
248+
this._observability.recordEvent(
249+
'oauth_authorization',
250+
AppEventName.OauthAuthorizationError,
251+
oauthAuthorizeHttpFailureEventAttrs(
252+
error,
253+
'legacy',
254+
value,
255+
false
252256
)
253-
}),
254-
catchError((error) => {
255-
this._observability.recordEvent(
256-
'oauth_authorization',
257-
AppEventName.OauthAuthorizationError,
258-
oauthAuthorizeHttpFailureEventAttrs(
259-
error,
260-
'legacy',
261-
value,
262-
false
263-
)
264-
)
265-
return throwError(() => error)
266-
}),
267-
take(1),
268-
finalize(() => (this.loadingAuthorizeEndpoint = false))
269-
)
270-
.subscribe((data) => {
271-
this.redirectUrl.next(data.redirectUrl)
257+
);
258+
// Throw the error down to the final subscribe block
259+
return throwError(() => error);
272260
})
261+
);
273262
}
274263
})
275264
)
276-
.subscribe()
265+
.subscribe({
266+
next: (redirectUrl: string) => {
267+
console.log('Redirecting to:', redirectUrl)
268+
this.redirectUrl.next(redirectUrl)
269+
},
270+
error: (err) => {
271+
console.error('Authorization error:', err)
272+
this.loadingAuthorizeEndpoint = false
273+
},
274+
})
277275
}
278276

279277
getIconName(ScopeObject: Scope): string {

src/app/core/oauth/oauth.service.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class OauthService {
9999
)
100100
}
101101

102-
authorize(approved: boolean): Observable<RequestInfoForm> {
102+
authorize(approved: boolean): Observable<string> {
103103
const value: OauthAuthorize = {
104104
// tslint:disable-next-line: max-line-length
105105
// TODO @angel please confirm that persistentTokenEnabled is always true https://github.com/ORCID/ORCID-Source/blob/master/orcid-web/src/main/webapp/static/javascript/ng1Orcid/app/modules/oauthAuthorization/oauthAuthorization.component.ts#L161
@@ -123,7 +123,8 @@ export class OauthService {
123123
),
124124
tap((requestInfo) => {
125125
this.requestInfoSubject.next(requestInfo)
126-
})
126+
}),
127+
map((requestInfo) => requestInfo.redirectUrl)
127128
)
128129
}
129130

@@ -157,12 +158,11 @@ export class OauthService {
157158
observe: 'response',
158159
})
159160
.pipe(
160-
map((res: HttpResponse<any>) => {
161+
switchMap((res: HttpResponse<any>) => {
161162
if (res.body && res.body['error']) {
162-
if (res.body['error'] == 'access_denied') {
163+
if (res.body['error'] === 'access_denied') {
163164
// Not a server error per see, just a user denied the authorization
164-
165-
return res.body['uri']
165+
return of(res.body['uri'])
166166
} else {
167167
this._observability.recordSimpleEvent(
168168
AppEventName.OauthAuthorizeAuthServerErrorBody,
@@ -175,13 +175,20 @@ export class OauthService {
175175
client_id: data?.clientId,
176176
}
177177
)
178-
this._errorHandler.handleError(
179-
res.body,
178+
const errorMessage =
179+
res.body['error_description'] ||
180+
'Authorization failed on server'
181+
const authError = new Error(errorMessage)
182+
183+
authError.name = res.body['error'] || 'AuthError'
184+
185+
return this._errorHandler.handleError(
186+
authError,
180187
ERROR_REPORT.STANDARD_VERBOSE
181188
)
182189
}
183190
} else {
184-
return res.headers.get('location')
191+
return of(res.headers.get('location'))
185192
}
186193
}),
187194
catchError((error) =>

0 commit comments

Comments
 (0)