Skip to content

Commit

Permalink
Merge pull request #12 from readdle/spark2
Browse files Browse the repository at this point in the history
Merge: main branch spark2 into calendars
  • Loading branch information
bolgov-pwr authored Jan 15, 2025
2 parents 3a0c146 + d3d050f commit 2b0ed5a
Show file tree
Hide file tree
Showing 45 changed files with 1,041 additions and 425 deletions.
9 changes: 5 additions & 4 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

---
title: 'Bug report'
labels: bug
---

### Description:

Expand All @@ -23,12 +26,10 @@

### Library version:
- [ ] head
- [ ] v2.1.0
- [ ] v2.0.0
- [ ] v1.4.1
- [ ] v1.2.1
- [ ] v1.2 (Swift 4.0)
- [ ] v1.0.0
- [ ] v0.6
- [ ] other: (Please fill in the version you are using.)

### Xcode version:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build
on: push
jobs:
build:
name: build
runs-on: macOS-10.14
env:
DEVELOPER_DIR: /Applications/Xcode_11.1.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 1
- name: Swift build
run: |
sdk=`xcrun -sdk iphonesimulator -show-sdk-path`
sdkVersion=`echo $sdk | sed -E 's/.*iPhoneSimulator(.*)\.sdk/\1/'`
swift build -Xswiftc "-sdk" -Xswiftc "$sdk" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios$sdkVersion-simulator"
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint
on: push
jobs:
lint:
name: Lint
runs-on: macOS-10.14
steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 1
- name: Install swiftlint
run: |
brew install swiftlint
env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
- name: Code Lint
run: |
swiftlint --strict
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test
on: push
jobs:
build:
name: test
runs-on: macOS-10.14
env:
DEVELOPER_DIR: /Applications/Xcode_11.1.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 1
- name: Swift test
run: |
sdk=`xcrun -sdk iphonesimulator -show-sdk-path`
sdkVersion=`echo $sdk | sed -E 's/.*iPhoneSimulator(.*)\.sdk/\1/'`
swift test -Xswiftc "-sdk" -Xswiftc "$sdk" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios$sdkVersion-simulator"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Xcode (from gitignore.io)
build/
.build
.swiftpm
*.pbxuser
!default.pbxuser
*.mode1v3
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
language: objective-c
osx_image: xcode11
osx_image: xcode11.1
env:
global:
- LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8
- PROJECT=OAuthSwift.xcodeproj
- IOS_FRAMEWORK_SCHEME="OAuthSwift"
- MACOS_FRAMEWORK_SCHEME="OAuthSwiftMacOS"
- IOS_SDK=iphonesimulator13
- IOS_SDK=iphonesimulator13.1
- MACOS_SDK=macosx10.15
matrix:
- DESTINATION="OS=13.0,name=iPhone 8" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK"
- DESTINATION="OS=13.1,name=iPhone 8" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK"
- DESTINATION="arch=x86_64" SCHEME="$MACOS_FRAMEWORK_SCHEME" SDK="$MACOS_SDK"
before_install:
- bundle install
Expand Down
5 changes: 5 additions & 0 deletions Demo/Common/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ extension AppDelegate: UIApplicationDelegate {
applicationHandle(url: url)
return true
}

class var sharedInstance: AppDelegate {
return UIApplication.shared.delegate as! AppDelegate
}

}

#elseif os(OSX)
Expand Down
52 changes: 37 additions & 15 deletions Demo/Common/FormViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum URLHandlerType {
case `internal`
case external
case safari
case asWeb
}


Expand Down Expand Up @@ -82,6 +83,7 @@ class FormViewController: FormViewControllerType {
#if os(iOS)
@IBOutlet weak var safariURLHandler: UISwitch!
@IBOutlet weak var safariURLHandlerView: UITableViewCell!
@IBOutlet weak var asWebURLHandler: UISwitch!
#endif

@IBAction func ok(_ sender: AnyObject?) {
Expand Down Expand Up @@ -115,9 +117,12 @@ class FormViewController: FormViewControllerType {
urlHandlerType = .`internal`
}
#if os(iOS)
if safariURLHandler == sender {
urlHandlerType = .safari
}
if safariURLHandler == sender {
urlHandlerType = .safari
}
if asWebURLHandler == sender {
urlHandlerType = .asWeb
}
#endif
} else {
// set another...
Expand All @@ -128,9 +133,12 @@ class FormViewController: FormViewControllerType {
urlHandlerType = .external
}
#if os(iOS)
if safariURLHandler == sender {
urlHandlerType = .`internal`
}
if safariURLHandler == sender {
urlHandlerType = .`internal`
}
if asWebURLHandler == sender {
urlHandlerType = .`internal`
}
#endif
}
}
Expand All @@ -144,32 +152,46 @@ class FormViewController: FormViewControllerType {
return .`internal`
}
#if os(iOS)
if safariURLHandler.isOn {
return .safari
}
if safariURLHandler.isOn {
return .safari
}
if asWebURLHandler.isOn {
return .asWeb
}
#endif
return .`internal`
}
set {
switch newValue {
case .external:
externalURLHandler.setOn(true, animated: false)
externalURLHandler.setOn(true, animated: true)
internalURLHandler.setOn(false, animated: true)
#if os(iOS)
safariURLHandler.setOn(false, animated: true)
safariURLHandler.setOn(false, animated: true)
asWebURLHandler.setOn(false, animated: true)
#endif
break
case .`internal`:
internalURLHandler.setOn(true, animated: false)
internalURLHandler.setOn(true, animated: true)
externalURLHandler.setOn(false, animated: true)
#if os(iOS)
safariURLHandler.setOn(false, animated: true)
safariURLHandler.setOn(false, animated: true)
asWebURLHandler.setOn(false, animated: true)
#endif
break
case .safari:
#if os(iOS)
safariURLHandler.setOn(true, animated: false)
#endif
safariURLHandler.setOn(true, animated: true)
asWebURLHandler.setOn(false, animated: true)
#endif
externalURLHandler.setOn(false, animated: true)
internalURLHandler.setOn(false, animated: true)
break
case .asWeb:
#if os(iOS)
safariURLHandler.setOn(false, animated: true)
asWebURLHandler.setOn(true, animated: true)
#endif
externalURLHandler.setOn(false, animated: true)
internalURLHandler.setOn(false, animated: true)
break
Expand Down
3 changes: 2 additions & 1 deletion Demo/Common/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "oauthswift-icon-181.png",
"scale" : "1x"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Demo/Common/Services.plist
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,12 @@
<key>consumerKey</key>
<string></string>
</dict>
<key>Twitch</key>
<dict>
<key>consumerSecret</key>
<string></string>
<key>consumerKey</key>
<string></string>
</dict>
</dict>
</plist>
62 changes: 61 additions & 1 deletion Demo/Common/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ extension ViewController {
doOAuthNoun(parameters)
case "Lyft":
doOAuthLyft(parameters)
case "Twitch":
doOAuthTwitch(parameters)
default:
print("\(service) not implemented")
}
Expand Down Expand Up @@ -1350,6 +1352,44 @@ extension ViewController {
}
}
}

// MARK: Twitch
func doOAuthTwitch(_ serviceParameters: [String:String]){
let oauthswift = OAuth2Swift(
consumerKey: serviceParameters["consumerKey"]!,
consumerSecret: serviceParameters["consumerSecret"]!,
authorizeUrl: "https://id.twitch.tv/oauth2/authorize",
accessTokenUrl: "https://id.twitch.tv/oauth2/token",
responseType: "code",
contentType: "application/json"
)
self.oauthswift = oauthswift
oauthswift.authorizeURLHandler = getURLHandler()
let state = generateState(withLength: 20)
let _ = oauthswift.authorize(
withCallbackURL: URL(string: "oauth-swift://oauth-callback/twitch")!, scope: "user_read", state: state) { result in
switch result {
case .success(let (credential, _, _)):
self.showTokenAlert(name: serviceParameters["name"], credential: credential)
self.testTwitch(oauthswift,credential.oauthToken)
case .failure(let error):
print(error.description)
}
}
}

func testTwitch(_ oauthswift: OAuth2Swift, _ oauthToken: String) {
let _ = oauthswift.client.get(
"https://api.twitch.tv/kraken/user?oauth_token=\(oauthToken)", headers: ["Accept":"application/vnd.twitchtv.v5+json"]) { result in
switch result {
case .success(let response):
let dataString = response.string!
print(dataString)
case .failure(let error):
print(error)
}
}
}
}

let services = Services()
Expand Down Expand Up @@ -1512,8 +1552,15 @@ extension ViewController {
}
#endif
return OAuthSwiftOpenURLExternally.sharedInstance
case .asWeb:
#if os(iOS)
if #available(iOS 13.0, *) {
return ASWebAuthenticationURLHandler(callbackUrlScheme: "oauth-swift://oauth-callback/", presentationContextProvider: self)
}
#endif
return OAuthSwiftOpenURLExternally.sharedInstance
}

#if os(OSX)
// a better way is
// - to make this ViewController implement OAuthSwiftURLHandlerType and assigned in oauthswift object
Expand Down Expand Up @@ -1626,6 +1673,19 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate {
}
#endif

#if os(iOS)
import SafariServices
#if canImport(AuthenticationServices)
import AuthenticationServices
#endif
@available(iOS 13.0, macCatalyst 13.0, *)
extension ViewController: ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return UIApplication.shared.topWindow ?? ASPresentationAnchor()
}
}
#endif

struct FormViewControllerData {
var key: String
var secret: String
Expand Down
Loading

0 comments on commit 2b0ed5a

Please sign in to comment.