-
Notifications
You must be signed in to change notification settings - Fork 42
Fix/login 403 logged in and 401 when not logged in #711
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
base: post-milestone3m
Are you sure you want to change the base?
Changes from all commits
607f064
64151b4
55a2c05
02b2774
e9f087b
fbe3371
50b5613
4fe6ab2
f27309a
5dac8db
97e32b0
ab89cf5
8f043a3
f49e0fd
41886e7
1ce28f2
7de7e4c
c3a16a3
4a9bd3f
0c0c839
fd9904a
4854ebb
f6a5180
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,12 @@ export async function ensureLoadedPreferences ( | |
| try { | ||
| context = await ensureLoadedProfile(context) | ||
|
|
||
| if (!context.me || !context.publicProfile) { | ||
| context.preferencesFileError = | ||
| context.preferencesFileError || 'Not logged in, so preferences were not loaded.' | ||
| return context | ||
| } | ||
|
|
||
| // console.log('back in Solid UI after logInLoadProfile', context) | ||
| const preferencesFile = await loadPreferences(context.me as NamedNode) | ||
| if (progressDisplay) { | ||
|
|
@@ -134,27 +140,33 @@ export async function ensureLoadedPreferences ( | |
| context.preferencesFile = preferencesFile | ||
| } catch (err) { | ||
| let m2: string | ||
| if (err instanceof UnauthorizedError) { | ||
| const errorMessage = err instanceof Error ? err.message : `${err}` | ||
| if (err instanceof UnauthorizedError || /(?:status:\s*401\b|unauthorized)/i.test(errorMessage)) { | ||
| m2 = | ||
| 'Oops — you are not authenticated (properly logged in), so SolidOS cannot read your preferences file. Try logging out and then logging back in.' | ||
| alert(m2) | ||
| 'Not logged in, so preferences were not loaded.' | ||
| context.preferencesFileError = m2 | ||
| debug.warn(m2) | ||
| return context | ||
|
Comment on lines
+143
to
+149
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot apply changes based on this feedback
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit |
||
| } else if (err instanceof CrossOriginForbiddenError) { | ||
| m2 = `Unauthorized: Assuming preference file blocked for origin ${window.location.origin}` | ||
| context.preferencesFileError = m2 | ||
| return context | ||
| } else if (err instanceof SameOriginForbiddenError) { | ||
| m2 = | ||
| 'You are not authorized to read your preference file. This may be because you are using an untrusted web app.' | ||
| context.preferencesFileError = m2 | ||
| debug.warn(m2) | ||
| return context | ||
| } else if (err instanceof NotEditableError) { | ||
| m2 = | ||
| 'You are not authorized to edit your preference file. This may be because you are using an untrusted web app.' | ||
| context.preferencesFileError = m2 | ||
| debug.warn(m2) | ||
| return context | ||
| } else if (err instanceof WebOperationError) { | ||
| m2 = | ||
| 'You are not authorized to edit your preference file. This may be because you are using an untrusted web app.' | ||
| context.preferencesFileError = m2 | ||
| debug.warn(m2) | ||
| } else if (err instanceof FetchError) { | ||
| m2 = `Strange: Error ${err.status} trying to read your preference file.${err.message}` | ||
|
|
@@ -177,20 +189,66 @@ export async function ensureLoadedPreferences ( | |
| export async function ensureLoadedProfile ( | ||
| context: AuthenticationContext | ||
| ): Promise<AuthenticationContext> { | ||
| const handleNotLoggedInProfile = (logMessage: (message: string) => void) => { | ||
| const notLoggedInMessage = 'Not logged in, so profile was not loaded.' | ||
| const notLoggedInMessageKey = 'not-logged-in-profile' | ||
| logMessage(notLoggedInMessage) | ||
| if (context.div && context.dom) { | ||
| const existingMessage = context.div.querySelector( | ||
| `[data-login-message="${notLoggedInMessageKey}"]` | ||
| ) | ||
| if (!existingMessage) { | ||
| const errorBlock = widgets.errorMessageBlock(context.dom, notLoggedInMessage, 'white') | ||
| errorBlock.setAttribute('data-login-message', notLoggedInMessageKey) | ||
| context.div.appendChild(errorBlock) | ||
|
Comment on lines
+197
to
+203
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot apply changes based on this feedback
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit |
||
| } | ||
| } | ||
|
SharonStrats marked this conversation as resolved.
|
||
| return context | ||
| } | ||
|
|
||
| if (context.publicProfile) { | ||
| return context | ||
| } // already done | ||
| let logInContext: AuthenticationContext | undefined | ||
| try { | ||
| const logInContext = await ensureLoggedIn(context) | ||
| logInContext = await ensureLoggedIn(context) | ||
| if (!logInContext.me) { | ||
|
SharonStrats marked this conversation as resolved.
|
||
| const webId = authSession.info?.webId || await authn.checkUser() | ||
| if (webId) { | ||
| authn.saveUser(webId, logInContext) | ||
| } | ||
| } | ||
| if (!logInContext.me) { | ||
| throw new Error('Could not log in') | ||
| return handleNotLoggedInProfile(debug.log) | ||
| } | ||
| context.publicProfile = await loadProfile(logInContext.me) | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : `${err}` | ||
| if (err instanceof UnauthorizedError || /(status:\s*401\b|unauthorized)/i.test(message)) { | ||
| return handleNotLoggedInProfile(debug.warn) | ||
| } | ||
| const loggedInUser = logInContext && logInContext.me | ||
| const isNonFatalProfileSideLoadFailure = | ||
| !!loggedInUser && | ||
| ( | ||
| err instanceof CrossOriginForbiddenError || | ||
| err instanceof SameOriginForbiddenError || | ||
| /status:\s*403\b|forbidden/i.test(message) || | ||
| /cancel/i.test(message) | ||
| ) | ||
| if (isNonFatalProfileSideLoadFailure) { | ||
| debug.warn(`Unable to load all profile-linked resources; continuing as logged in user: ${message}`) | ||
| context.publicProfile = loggedInUser!.doc() | ||
| return context | ||
| } | ||
| if (context.div && context.dom) { | ||
| context.div.appendChild(widgets.errorMessageBlock(context.dom, err.message)) | ||
| context.div.appendChild(widgets.errorMessageBlock(context.dom, message)) | ||
| } | ||
| const loginError = new Error(`Can't log in: ${message}`) as Error & { cause?: unknown } | ||
| if (err instanceof Error) { | ||
| loginError.cause = err | ||
| } | ||
| throw new Error(`Can't log in: ${err}`) | ||
| throw loginError | ||
| } | ||
| return context | ||
| } | ||
|
|
@@ -784,6 +842,13 @@ export function selectWorkspace ( | |
|
|
||
| function displayOptions (context) { | ||
| // console.log('displayOptions!', context) | ||
| if (!context.preferencesFile) { | ||
|
SharonStrats marked this conversation as resolved.
|
||
| say( | ||
| context.preferencesFileError || 'Preferences not available.' | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| async function makeNewWorkspace (_event) { | ||
| const row = table.appendChild(dom.createElement('tr')) | ||
| const cell = row.appendChild(dom.createElement('td')) | ||
|
|
@@ -1047,11 +1112,11 @@ export function newAppInstance ( | |
| * and/or a developer | ||
| */ | ||
| export async function getUserRoles (): Promise<Array<NamedNode>> { | ||
| const sessionInfo = authSession.info | ||
| const sessionInfo = authSession.info | ||
| if (!sessionInfo?.isLoggedIn || !sessionInfo?.webId) { | ||
| return [] | ||
| } | ||
|
|
||
| const currentUser = authn.currentUser() | ||
| if (!currentUser) { | ||
| return [] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.