Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

swift - Twitch API Authentication using WKWebView

As a beginner in coding, I am trying to create user login by using Twitch API on my WebView in Xcode. I manage to get user to sign and authorize however, screen goes all white and don't know what to do afterwards. Following is the code that use,

let twitchApiUrl = "https://id.twitch.tv/oauth2/authorize?client_id=(clientId)&redirect_uri=(registeredUri)&response_type=token+id_token&scope=openid"
    let registeredUri = "https://loginpage"
    let clientId = "yu4sqhnxv3qazgpfecrhtsxn2k2ttm"
    
    
    class ViewController: UIViewController, WKNavigationDelegate {
        
        var webView: WKWebView!
        
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view.
        
        }
        
        @IBAction func twitchLogin(_ sender: Any) {
            
            // WebView Access
            webView = WKWebView()
            webView.navigationDelegate = self
            view = webView
            
            // Twitch API Request
            let request = NSURLRequest(url: NSURL(string: twitchApiUrl)! as URL)
            webView.load(request as URLRequest)
            
        }
        
        func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
            print("loaded")
        }
    }

I believe the problem is, my redirect URI is not sending it back to the application after authorisation. I greatly appreciate if someone can clarify the issue.

Thanks

question from:https://stackoverflow.com/questions/65872504/twitch-api-authentication-using-wkwebview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...