-
Notifications
You must be signed in to change notification settings - Fork 9
v1.2.3: Support Auto Switch Authentication #46
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
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3b94c23
update github action
SYM01 e8467f8
minor change to System profile
SYM01 6426011
Build(deps): Bump nanoid from 3.3.7 to 3.3.8 (#21)
dependabot[bot] 8292e79
Avoid blocking 401 authentication request (#22) (#23)
SYM01 ca949f6
Support Firefox (#18)
SYM01 33c0d0e
[i18n] Updates for file public/_locales/en/messages.json (#25)
transifex-integration[bot] 1beabb4
Merge branch 'main' into develop
SYM01 ca27aed
sentry integration (#29)
SYM01 accb03b
[WIP] support exporting
SYM01 654f865
[WIP] support import/export settings (#7)
SYM01 8f048df
Support import/export profiles and close #7 (#30)
SYM01 29f8506
Merge remote-tracking branch 'origin/main' into develop
SYM01 76f9233
optimized description
SYM01 9abae03
[i18n] Updates for file public/_locales/en/messages.json (#32)
transifex-integration[bot] 204d459
fix an import issue (#33) (#35)
SYM01 438b9e4
Merge branch 'main' into develop
SYM01 fd571be
optimized sentry release
SYM01 9b10c01
Optimize Development Flow (#37)
SYM01 5c61a9b
UX improvement and close #28 (#38)
SYM01 d688606
[i18n] Updates for file public/_locales/en/messages.json (#40)
transifex-integration[bot] 4213518
Support Authentication in Auto Switch Profiles, fixing #34 (#45)
SYM01 ea212a1
Merge remote-tracking branch 'origin/main' into develop
SYM01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import type { ProxyAuthInfo, ProxyProfile } from "../profile"; | ||
| import type { ProfileLoader } from "./profile2config"; | ||
|
|
||
| export class ProfileAuthProvider { | ||
| private searchedProfiles: Set<string> = new Set(); | ||
|
|
||
| constructor( | ||
| private profile: ProxyProfile, | ||
| private profileLoader?: ProfileLoader | ||
| ) {} | ||
|
|
||
| async getAuthInfos(host: string, port: number): Promise<ProxyAuthInfo[]> { | ||
| this.searchedProfiles.clear(); | ||
| return this.getAuthInfosForProfile(host, port, this.profile); | ||
| } | ||
|
|
||
| private async getAuthInfosForProfile( | ||
| host: string, | ||
| port: number, | ||
| profile: ProxyProfile | ||
| ): Promise<ProxyAuthInfo[]> { | ||
| // avoid infinite loop | ||
| if (this.searchedProfiles.has(profile.profileID)) { | ||
| return []; | ||
| } | ||
| this.searchedProfiles.add(profile.profileID); | ||
|
|
||
| switch (profile.proxyType) { | ||
| case "proxy": | ||
| return this.getAuthInfosForProxyProfile(host, port, profile); | ||
| case "auto": | ||
| return this.getAuthInfosForAutoProfile(host, port, profile); | ||
|
|
||
| default: | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| private async getAuthInfosForProxyProfile( | ||
| host: string, | ||
| port: number, | ||
| profile: ProxyProfile & { proxyType: "proxy" } | ||
| ): Promise<ProxyAuthInfo[]> { | ||
| const ret: ProxyAuthInfo[] = []; | ||
| const auths = [ | ||
| profile.proxyRules.default, | ||
| profile.proxyRules.ftp, | ||
| profile.proxyRules.http, | ||
| profile.proxyRules.https, | ||
| ]; | ||
|
|
||
| // check if there's any matching host and port | ||
| auths.map((item) => { | ||
| if (!item) return; | ||
|
|
||
| if ( | ||
| item.host == host && | ||
| (item.port === undefined || item.port == port) && | ||
| item.auth | ||
| ) { | ||
| ret.push(item.auth); | ||
| } | ||
| }); | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| private async getAuthInfosForAutoProfile( | ||
| host: string, | ||
| port: number, | ||
| profile: ProxyProfile & { proxyType: "auto" } | ||
| ): Promise<ProxyAuthInfo[]> { | ||
| const ret: ProxyAuthInfo[] = []; | ||
|
|
||
| for (const rule of profile.rules) { | ||
| if (rule.type == "disabled") { | ||
| continue; | ||
| } | ||
|
|
||
| const profile = await this.loadProfile(rule.profileID); | ||
| if (!profile) { | ||
| continue; | ||
| } | ||
|
|
||
| const authInfos = await this.getAuthInfosForProfile(host, port, profile); | ||
| authInfos && ret.push(...authInfos); | ||
| } | ||
|
|
||
| // don't forget the default profile | ||
| const defaultProfile = await this.loadProfile(profile.defaultProfileID); | ||
| if (defaultProfile) { | ||
| const authInfos = await this.getAuthInfosForProfile( | ||
| host, | ||
| port, | ||
| defaultProfile | ||
| ); | ||
| authInfos && ret.push(...authInfos); | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| private async loadProfile( | ||
| profileID: string | ||
| ): Promise<ProxyProfile | undefined> { | ||
| if (!this.profileLoader) { | ||
| return; | ||
| } | ||
|
|
||
| return await this.profileLoader(profileID); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there's a
console.log("test")statement here. Was this intended for debugging and should it be removed before merging?