You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class ViewModel: ObservableObject { @published var accessToken: String = ""
func login() {
let oauthswift = OAuth2Swift(
consumerKey: "",
consumerSecret: "",
authorizeUrl: "https://www.bungie.net/en/oauth/authorize",
accessTokenUrl: "/platform/app/oauth/token/",
responseType: "code"
)
let handler = OAuthHandler()
oauthswift.authorizeURLHandler = handler
handler.viewController = UIApplication.shared.windows.first?.rootViewController
let state = generateState(withLength: 20) // Genera un estado único para cada solicitud de autorización
let parameters: [String: Any] = [
"client_id": "cliient number" // Agrega tu API Key aquí
]
oauthswift.authorize(
withCallbackURL: URL(string: "com.example.ui:/")!,
scope: "",
state: state,
parameters: parameters,
completionHandler: { result in
switch result {
case .success(let (credential, _, _)):
self.accessToken = credential.oauthToken
print("Access token: \(credential.oauthToken)")
case .failure(let error):
print(error.localizedDescription)
}
}
)
}
// Resto del código de ViewModel...
}
struct ContentView: View { @StateObject var viewModel = ViewModel()
var body: some View {
VStack {
Text("Access token: (viewModel.accessToken)")
Button("Login") {
viewModel.login()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
// Resto del código de ContentView...
`
OAuth Provider? (Twitter, Github, ..):
Bungie
OAuth Version:
Version 1
[x ] Version 2
OS (Please fill the version) :
iOS :
OSX :
TVOS :
WatchOS :
Installation method:
Carthage
CocoaPods
Swift Package Manager
Manually
Library version:
head
[ x] v2.1.0
v2.0.0
v1.4.1
other: (Please fill in the version you are using.)
Xcode version:
11.4 (Swift 5.2)
11.x (Swift 5.1)
[ x] 10.x (Swift 5.0)
other: (Please fill in the version you are using.)
objective c
The text was updated successfully, but these errors were encountered:
whern debug my code in login funtion,debug mode drops when authorize my application,drops whithout any error message from server or code,my scheme url is com.exmaple.ui,Thanks
Description:
same as title ,add my code
`import SwiftUI
import Alamofire
import OAuthSwift
import SafariServices
class OAuthHandler: NSObject, OAuthSwiftURLHandlerType {
weak var viewController: UIViewController?
}
class ViewModel: ObservableObject {
@published var accessToken: String = ""
}
struct ContentView: View {
@StateObject var viewModel = ViewModel()
var body: some View {
VStack {
Text("Access token: (viewModel.accessToken)")
Button("Login") {
viewModel.login()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
// Resto del código de ContentView...
`
OAuth Provider? (Twitter, Github, ..):
Bungie
OAuth Version:
OS (Please fill the version) :
Installation method:
Library version:
Xcode version:
11.4 (Swift 5.2)
11.x (Swift 5.1)
[
x]
10.x (Swift 5.0)other: (Please fill in the version you are using.)
objective c
The text was updated successfully, but these errors were encountered: