mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-02-21 23:32:07 +00:00
Hide OpenVPN password if provider does not require it (#970)
This commit is contained in:
parent
14ce23f25b
commit
a2544b33ac
@ -41,7 +41,7 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "aa85d745f8419def59ef630501d71a491a32829e"
|
"revision" : "cfbcfd7106ee21781cb637eef8e15ed9a1463bce"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@ let package = Package(
|
|||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "aa85d745f8419def59ef630501d71a491a32829e"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "cfbcfd7106ee21781cb637eef8e15ed9a1463bce"),
|
||||||
// .package(path: "../../passepartoutkit-source"),
|
// .package(path: "../../passepartoutkit-source"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
||||||
|
@ -18,7 +18,12 @@
|
|||||||
"fullName": "Mullvad",
|
"fullName": "Mullvad",
|
||||||
"vpn": ["ovpn"],
|
"vpn": ["ovpn"],
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"OpenVPN": {}
|
"OpenVPN": {
|
||||||
|
"credentials": {
|
||||||
|
"purpose": "web",
|
||||||
|
"options": ["noPassword"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"name": "nordvpn",
|
"name": "nordvpn",
|
||||||
|
@ -58,6 +58,9 @@ public struct OpenVPNCredentialsView: View {
|
|||||||
@State
|
@State
|
||||||
private var builder = OpenVPN.Credentials.Builder()
|
private var builder = OpenVPN.Credentials.Builder()
|
||||||
|
|
||||||
|
@State
|
||||||
|
private var providerConfiguration: OpenVPN.Credentials.ProviderConfiguration?
|
||||||
|
|
||||||
@State
|
@State
|
||||||
private var paywallReason: PaywallReason?
|
private var paywallReason: PaywallReason?
|
||||||
|
|
||||||
@ -89,29 +92,8 @@ public struct OpenVPNCredentialsView: View {
|
|||||||
}
|
}
|
||||||
.themeManualInput()
|
.themeManualInput()
|
||||||
.modifier(PaywallModifier(reason: $paywallReason))
|
.modifier(PaywallModifier(reason: $paywallReason))
|
||||||
.onLoad {
|
.onLoad(perform: onLoad)
|
||||||
builder = credentials?.builder() ?? OpenVPN.Credentials.Builder()
|
.onChange(of: builder, perform: onChange)
|
||||||
builder.otp = nil
|
|
||||||
if isAuthenticating {
|
|
||||||
switch builder.otpMethod {
|
|
||||||
case .none:
|
|
||||||
focusedField = .username
|
|
||||||
|
|
||||||
default:
|
|
||||||
focusedField = .otp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onChange(of: builder) {
|
|
||||||
var copy = $0
|
|
||||||
if isEligibleForInteractiveLogin {
|
|
||||||
copy.otp = copy.otp ?? ""
|
|
||||||
} else {
|
|
||||||
copy.otpMethod = .none
|
|
||||||
copy.otp = nil
|
|
||||||
}
|
|
||||||
credentials = copy.build()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +133,9 @@ private extension OpenVPNCredentialsView {
|
|||||||
Group {
|
Group {
|
||||||
if !isAuthenticating || builder.otpMethod == .none {
|
if !isAuthenticating || builder.otpMethod == .none {
|
||||||
usernameField
|
usernameField
|
||||||
passwordField
|
if !ignoresPassword {
|
||||||
|
passwordField
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if isEligibleForInteractiveLogin, isAuthenticating, builder.otpMethod != .none {
|
if isEligibleForInteractiveLogin, isAuthenticating, builder.otpMethod != .none {
|
||||||
otpField
|
otpField
|
||||||
@ -162,7 +146,7 @@ private extension OpenVPNCredentialsView {
|
|||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var guidanceSection: some View {
|
var guidanceSection: some View {
|
||||||
if case .specific(let url) = providerPurpose, let url {
|
if let url = providerConfiguration?.url {
|
||||||
Link(Strings.Modules.Openvpn.Credentials.Guidance.link, destination: url)
|
Link(Strings.Modules.Openvpn.Credentials.Guidance.link, destination: url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,11 +155,10 @@ private extension OpenVPNCredentialsView {
|
|||||||
if isAuthenticating {
|
if isAuthenticating {
|
||||||
return builder.otpMethod.localizedDescription(style: .approachDescription)
|
return builder.otpMethod.localizedDescription(style: .approachDescription)
|
||||||
.nilIfEmpty
|
.nilIfEmpty
|
||||||
} else if let providerPurpose {
|
} else if let providerConfiguration {
|
||||||
switch providerPurpose {
|
switch providerConfiguration.purpose {
|
||||||
case .web:
|
case .web:
|
||||||
return Strings.Modules.Openvpn.Credentials.Guidance.web
|
return Strings.Modules.Openvpn.Credentials.Guidance.web
|
||||||
|
|
||||||
case .specific:
|
case .specific:
|
||||||
return Strings.Modules.Openvpn.Credentials.Guidance.specific
|
return Strings.Modules.Openvpn.Credentials.Guidance.specific
|
||||||
}
|
}
|
||||||
@ -229,11 +212,39 @@ private extension OpenVPNCredentialsView {
|
|||||||
[.none, .append, .encode]
|
[.none, .append, .encode]
|
||||||
}
|
}
|
||||||
|
|
||||||
var providerPurpose: OpenVPN.Credentials.ProviderPurpose? {
|
var ignoresPassword: Bool {
|
||||||
guard let providerId, let metadata = providerManager.provider(withId: providerId) else {
|
providerConfiguration?.options?.contains(.noPassword) ?? false
|
||||||
return nil
|
}
|
||||||
|
|
||||||
|
func onLoad() {
|
||||||
|
if let providerId, let metadata = providerManager.provider(withId: providerId) {
|
||||||
|
providerConfiguration = OpenVPN.Credentials.configuration(forProvider: metadata)
|
||||||
}
|
}
|
||||||
return OpenVPN.Credentials.purpose(forProvider: metadata)
|
builder = credentials?.builder() ?? OpenVPN.Credentials.Builder()
|
||||||
|
if ignoresPassword {
|
||||||
|
builder.password = ""
|
||||||
|
}
|
||||||
|
builder.otp = nil
|
||||||
|
if isAuthenticating {
|
||||||
|
switch builder.otpMethod {
|
||||||
|
case .none:
|
||||||
|
focusedField = .username
|
||||||
|
|
||||||
|
default:
|
||||||
|
focusedField = .otp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func onChange(_ builder: OpenVPN.Credentials.Builder) {
|
||||||
|
var copy = builder
|
||||||
|
if isEligibleForInteractiveLogin {
|
||||||
|
copy.otp = copy.otp ?? ""
|
||||||
|
} else {
|
||||||
|
copy.otpMethod = .none
|
||||||
|
copy.otp = nil
|
||||||
|
}
|
||||||
|
credentials = copy.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user