-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aayush Pokharel
authored and
Aayush Pokharel
committed
Dec 23, 2023
1 parent
13fe6d8
commit ece417d
Showing
18 changed files
with
340 additions
and
166 deletions.
There are no files selected for viewing
This file contains 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
23 changes: 23 additions & 0 deletions
23
NativeTwitch/Assets.xcassets/transparentIcon.imageset/Contents.json
This file contains 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,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "transparentIcon.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+1.49 KB
NativeTwitch/Assets.xcassets/transparentIcon.imageset/transparentIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.64 KB
NativeTwitch/Assets.xcassets/transparentIcon.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.42 KB
NativeTwitch/Assets.xcassets/transparentIcon.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
NativeTwitch/Assets.xcassets/twitchLogo.imageset/Contents.json
This file contains 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,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleURLTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleTypeRole</key> | ||
<string>Editor</string> | ||
<key>CFBundleURLName</key> | ||
<string>nativetwitch</string> | ||
<key>CFBundleURLSchemes</key> | ||
<array> | ||
<string>nativetwitch</string> | ||
</array> | ||
</dict> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains 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 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 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,58 @@ | ||
// | ||
// TwitchDeviceAuth.swift | ||
// NativeTwitch | ||
// | ||
// Created by Aayush Pokharel on 2023-12-19. | ||
// | ||
|
||
import Foundation | ||
import os | ||
|
||
class TwitchDeviceAuth { | ||
let logger = Logger(category: "🔑") | ||
|
||
let clientID: String = Constants.clientID | ||
let scope: String = Constants.scopes | ||
|
||
func startDeviceAuthorization() async throws -> (deviceCode: String, userCode: String, verificationUri: String) { | ||
logger.log("Starting Device Authorization") | ||
let url = URL(string: "https://id.twitch.tv/oauth2/device")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "POST" | ||
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") | ||
let bodyParameters = "client_id=\(clientID)&scopes=\(scope)" | ||
request.httpBody = bodyParameters.data(using: .utf8) | ||
|
||
let (data, _) = try await URLSession.shared.data(for: request) | ||
let json = try JSONSerialization.jsonObject(with: data) as! [String: Any] | ||
print("Start Device Authorization \(json)") | ||
guard let deviceCode = json["device_code"] as? String, | ||
let userCode = json["user_code"] as? String, | ||
let verificationUri = json["verification_uri"] as? String | ||
else { | ||
throw NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Invalid response data"]) | ||
} | ||
|
||
return (deviceCode, userCode, verificationUri) | ||
} | ||
|
||
func pollForToken(deviceCode: String) async throws -> String { | ||
logger.log("Polling for Token") | ||
let url = URL(string: "https://id.twitch.tv/oauth2/token")! | ||
var request = URLRequest(url: url) | ||
request.httpMethod = "POST" | ||
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") | ||
let bodyParameters = "client_id=\(clientID)&device_code=\(deviceCode)&grant_type=urn:ietf:params:oauth:grant-type:device_code" | ||
request.httpBody = bodyParameters.data(using: .utf8) | ||
|
||
let (data, _) = try await URLSession.shared.data(for: request) | ||
let json = try JSONSerialization.jsonObject(with: data) as! [String: Any] | ||
print("pollForToken \(json)") | ||
if let accessToken = json["access_token"] as? String { | ||
// Store the access token securely | ||
return accessToken | ||
} else { | ||
throw NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Authorization pending or other error"]) | ||
} | ||
} | ||
} |
This file contains 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 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.