Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OAuthSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@
repositoryURL = "https://github.com/codefiesta/OAuthKit.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.4.6;
minimumVersion = 1.4.8;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
16 changes: 15 additions & 1 deletion OAuthSample/Classes/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ struct ContentView: View {
}
case .receivedDeviceCode:
openWebView()
case .authorized(_, _):
case .authorized(_, let authorization):
dismissWebView()
makeAuthorizedRequest(authorization)
}
}

Expand All @@ -115,6 +116,19 @@ struct ContentView: View {
#endif
}

/// Sample of making an authorized request against Github.
/// - Parameter authorization: the authorization to use
private func makeAuthorizedRequest(_ authorization: OAuth.Authorization) {
Task {
let urlSession: URLSession = .init(configuration: .ephemeral)
let url: URL = .init(string: "https://api.github.com/users/codefiesta/repos")!
var request = URLRequest(url: url)
request.addAuthorization(auth: authorization)
let (data, _) = try await urlSession.data(for: request)
guard let string = String(data: data, encoding: .utf8) else { return }
debugPrint(string)
}
}
}

#Preview {
Expand Down