Skip to content

Commit

Permalink
backward compatibility with guardian domains
Browse files Browse the repository at this point in the history
  • Loading branch information
ionutmanolache-okta committed Jan 9, 2025
1 parent 0ed4950 commit 098c054
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
7 changes: 6 additions & 1 deletion Guardian/API/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ struct APIClient: API {

private extension URL {
func appendingPathComponentIfNeeded(_ pathComponent: String) -> URL {
lastPathComponent == pathComponent ? self : appendingPathComponent(pathComponent)
guard
lastPathComponent != pathComponent,
!absoluteString.hasSuffix("guardian.auth0.com"),
absoluteString.range(of: "guardian\\.[^\\.]*\\.auth0\\.com", options: .regularExpression) == nil
else { return self }
return appendingPathComponent(pathComponent)
}
}
22 changes: 18 additions & 4 deletions GuardianTests/GuardianSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,27 @@ class GuardianSpec: QuickSpec {
it("should return api with url only") {
expect(Guardian.api(url: URL(string: "https://samples.guardian.auth0.com")!)).toNot(beNil())
}
}

describe("adding path component") {
it("should not add path component to url with guardian.auth0.com suffix") {
expect(Guardian.api(url: URL(string: "https://samples.guardian.auth0.com")!).baseUrl.absoluteString).to(equal("https://samples.guardian.auth0.com"))
}

it("should not add path component to url with guardian.region.auth0.com") {
expect(Guardian.api(url: URL(string: "https://samples.guardian.en.auth0.com")!).baseUrl.absoluteString).to(equal("https://samples.guardian.en.auth0.com"))
}

it("should not add path component to custom url without guardian with already added path component") {
expect(Guardian.api(url: URL(string: "https://samples.auth0.com/appliance-mfa")!).baseUrl.absoluteString).to(equal("https://samples.auth0.com/appliance-mfa"))
}

it("should have base url with single 'appliance-mfa' component for passed url without this component") {
expect(Guardian.api(url: URL(string: "https://samples.guardian.auth0.com")!).baseUrl.absoluteString).to(equal("https://samples.guardian.auth0.com/appliance-mfa"))
it("should add path component to custom url without guardian without already added path component") {
expect(Guardian.api(url: URL(string: "https://samples.auth0.com")!).baseUrl.absoluteString).to(equal("https://samples.auth0.com/appliance-mfa"))
}

it("should have base url with single 'appliance-mfa' component for passed url with this component") {
expect(Guardian.api(url: URL(string: "https://samples.guardian.auth0.com/appliance-mfa")!).baseUrl.absoluteString).to(equal("https://samples.guardian.auth0.com/appliance-mfa"))
it("should add path component to custom url with guardian without already added path component") {
expect(Guardian.api(url: URL(string: "https://samples.guardian.some.thing.auth0.com")!).baseUrl.absoluteString).to(equal("https://samples.guardian.some.thing.auth0.com/appliance-mfa"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ github "auth0/Guardian.swift" ~> 1.4.2
import Guardian
```

Set the auth0 domains for your tenant:
Set the domain for your auth0 tenant:
```swift
let tenantDomain = "<tenant>.<region>.auth0.com"
```
Expand Down

0 comments on commit 098c054

Please sign in to comment.