Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url scheme no works,debug out #707

Open
1 of 17 tasks
oshju opened this issue May 17, 2023 · 2 comments
Open
1 of 17 tasks

url scheme no works,debug out #707

oshju opened this issue May 17, 2023 · 2 comments

Comments

@oshju
Copy link

oshju commented May 17, 2023

Description:

same as title ,add my code

`import SwiftUI
import Alamofire
import OAuthSwift
import SafariServices

class OAuthHandler: NSObject, OAuthSwiftURLHandlerType {
weak var viewController: UIViewController?

func handle(_ url: URL) {
    guard let viewController = viewController else {
        return
    }
    let safariViewController = SFSafariViewController(url: url)
    viewController.present(safariViewController, animated: true, completion: nil)
}

}

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

@phimage
Copy link
Member

phimage commented May 17, 2023

  • "noworks" is a bad bug description
  • then learn markdown
  • and do not do let oauthswift -> keep a ref on it (as class attribute or something else)
  • url scheme? you do not show us your url scheme conf, did you follow the doc
  • accessTokenUrl is bad

@oshju
Copy link
Author

oshju commented May 18, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants