diff --git a/.travis.yml b/.travis.yml index e7e7d5e..94f26d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ language: generic sudo: required dist: trusty -osx_image: xcode8.3 +osx_image: xcode9 before_install: - if [ $TRAVIS_OS_NAME == "osx" ]; then brew tap vapor/tap; @@ -23,7 +23,7 @@ script: - swift test after_success: - - eval "$(curl -sL https://raw.githubusercontent.com/vapor-community/swift/master/codecov)" + - eval "$(curl -sL https://raw.githubusercontent.com/vapor-community/swift/swift-4-codecov/codecov-swift4)" notifications: email: diff --git a/Package@swift-4.swift b/Package@swift-4.swift new file mode 100644 index 0000000..6b55ca5 --- /dev/null +++ b/Package@swift-4.swift @@ -0,0 +1,18 @@ +// swift-tools-version:4.0 + +import PackageDescription + +let package = Package( + name: "VaporOAuth", + products: [ + .library(name: "VaporOAuth", targets: ["VaporOAuth"]), + ], + dependencies: [ + .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.2.0")), + .package(url: "https://github.com/vapor/auth-provider.git", .upToNextMajor(from: "1.2.0")), + ], + targets: [ + .target(name: "VaporOAuth", dependencies: ["Vapor", "AuthProvider"]), + .testTarget(name: "VaporOAuthTests", dependencies: ["VaporOAuth"]), + ] +) diff --git a/README.md b/README.md index 9d814ca..2fcafea 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

- Language + Language Build Status @@ -40,7 +40,7 @@ Vapor OAuth can be added to your Vapor add with a simple provider. To get starte ```swift dependencies: [ ..., - .Package(url: "https://github.com/brokenhandsio/vapor-oauth", majorVersion: 0) + .package(url: "https://github.com/brokenhandsio/vapor-oauth", from: "0.6.0")) ] ``` diff --git a/Sources/VaporOAuth/Helper/Helper.swift b/Sources/VaporOAuth/Helper/Helper.swift index d216659..7ac47e9 100644 --- a/Sources/VaporOAuth/Helper/Helper.swift +++ b/Sources/VaporOAuth/Helper/Helper.swift @@ -60,7 +60,11 @@ extension Request { throw Abort(.forbidden) } + #if swift(>=4) + let token = String(authHeader[authHeader.index(authHeader.startIndex, offsetBy: 7)...]) + #else let token = authHeader.substring(from: authHeader.index(authHeader.startIndex, offsetBy: 7)) + #endif guard !token.isEmpty else { throw Abort(.forbidden) diff --git a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift index 271ff59..87c5916 100644 --- a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift +++ b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift @@ -57,7 +57,7 @@ class AuthorizationRequestTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift index 3b4ee40..ee39a4f 100644 --- a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift +++ b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift @@ -72,7 +72,7 @@ class AuthorizationResponseTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/DefaultImplementationTests/DefaultImplementationTests.swift b/Tests/VaporOAuthTests/DefaultImplementationTests/DefaultImplementationTests.swift index 941554d..e10d20a 100644 --- a/Tests/VaporOAuthTests/DefaultImplementationTests/DefaultImplementationTests.swift +++ b/Tests/VaporOAuthTests/DefaultImplementationTests/DefaultImplementationTests.swift @@ -34,7 +34,7 @@ class DefaultImplementationTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/AuthorizationCodeTokenTests.swift b/Tests/VaporOAuthTests/GrantTests/AuthorizationCodeTokenTests.swift index 48632f7..88624ed 100644 --- a/Tests/VaporOAuthTests/GrantTests/AuthorizationCodeTokenTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/AuthorizationCodeTokenTests.swift @@ -66,7 +66,7 @@ class AuthorizationCodeTokenTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/ClientCredentialsTokenTests.swift b/Tests/VaporOAuthTests/GrantTests/ClientCredentialsTokenTests.swift index 5a94fef..ef0bcff 100644 --- a/Tests/VaporOAuthTests/GrantTests/ClientCredentialsTokenTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/ClientCredentialsTokenTests.swift @@ -61,7 +61,7 @@ class ClientCredentialsTokenTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift b/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift index 3b14881..a9faad4 100644 --- a/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift @@ -88,7 +88,7 @@ class ImplicitGrantTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift b/Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift index 6ca15fc..a4ea1dd 100644 --- a/Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/PasswordGrantTokenTests.swift @@ -73,7 +73,7 @@ class PasswordGrantTokenTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift b/Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift index 300d6e4..8e46103 100644 --- a/Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/TokenRefreshTests.swift @@ -64,7 +64,7 @@ class TokenRefreshTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } diff --git a/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift b/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift index e4d19f3..66fa448 100644 --- a/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift +++ b/Tests/VaporOAuthTests/IntegrationTests/AuthCodeResourceServerTests.swift @@ -68,7 +68,7 @@ class AuthCodeResourceServerTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif } @@ -117,7 +117,7 @@ class AuthCodeResourceServerTests: XCTestCase { for queryPart in queryParts { if queryPart.hasPrefix("code=") { let codeStartIndex = queryPart.index(queryPart.startIndex, offsetBy: 5) - codePart = queryPart.substring(from: codeStartIndex) + codePart = String(queryPart[codeStartIndex...]) } } diff --git a/Tests/VaporOAuthTests/TokenIntrospectionTests/TokenIntrospectionTests.swift b/Tests/VaporOAuthTests/TokenIntrospectionTests/TokenIntrospectionTests.swift index d92c175..75e5e55 100644 --- a/Tests/VaporOAuthTests/TokenIntrospectionTests/TokenIntrospectionTests.swift +++ b/Tests/VaporOAuthTests/TokenIntrospectionTests/TokenIntrospectionTests.swift @@ -57,7 +57,7 @@ class TokenIntrospectionTests: XCTestCase { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) let thisClass = type(of: self) let linuxCount = thisClass.allTests.count - let darwinCount = Int(thisClass.defaultTestSuite().testCaseCount) + let darwinCount = Int(thisClass.defaultTestSuite.testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from allTests") #endif }