Skip to content

Instantly share code, notes, and snippets.

Avatar

Konstantin Lapine lapinek

View GitHub Profile
View OAuth2.AppAuth-iOS.SSO.Embedded.iOS-AppAuth-Basic.ViewController.WKScriptMessageHandler.swift
// ViewController.swift
// . . .
// MARK: Conforming to WKScriptMessageHandler protocol
extension ViewController: WKScriptMessageHandler {
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
print(#function)
if message.name == "callback", let messageBody = message.body as? String, let messageBodyData = messageBody.data(using: .utf8) {
View OAuth2.AppAuth-iOS.SSO.Embedded.AuthenticationResponse.swift
// AuthenticationResponse.swift
import Foundation
/**
Container for JSON callbacks expected from the authentication endpoint.
*/
struct AuthenticationResponse: Codable {
struct Callback: Codable {
let type: String?
View OAuth2.AppAuth-iOS.SSO.Embedded.WebViewController.js
// WebViewController.js
(function () {
if (window.webkit) {
var response = {
"authId": "authId",
"callbacks": [
{
"type": "Code",
"input": [],
View OAuth2.AppAuth-iOS.SSO.Embedded.iOS-AppAuth-Basic.ViewController.authorizeWithWebView.authorizeRp.swift
// ViewController.swift
// . . .
// MARK: Authorization methods
extension ViewController {
// . . .
/**
Authorizes the Relying Party with an OIDC Provider.
View OAuth2.AppAuth-iOS.SSO.Embedded.iOS-AppAuth-Basic.ViewController.WKNavigationDelegate.swift
// ViewController.swift
// . . .
// MARK: Delegate for the web view navigation events.
extension ViewController: WKNavigationDelegate {
// . . .
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
print("Navigation—action URL: ", navigationAction.request.url?.absoluteString ?? "")
View OAuth2.AppAuth-iOS.SSO.Embedded.iOS-AppAuth-Basic.ViewController.authorizeWithWebView.swift
// ViewController.swift
// . . .
// MARK: Authorization methods
extension ViewController {
// . . .
/**
Performs the authorization code flow using a web view.
View OAuth2.AppAuth-iOS.SSO.Embedded.iOS-AppAuth-Basic.ViewController.swift
// ViewController.swift
// . . .
class ViewController: UIViewController {
// . . .
/**
App Group name.
View OAuth2.AppAuth-iOS.SSO.Embedded.SSO-WebView-1.ViewController.swift
// ViewController.swift
import UIKit
class ViewController: UIViewController {
var webViewController: WebViewController!
// . . .
/**