Skip to content

feat(ios): same behavior as Android for code. #284

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
39 changes: 34 additions & 5 deletions ios/Plugin/GenericOAuth2Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ import AuthenticationServices

typealias JSObject = [String: Any]

public class MyOAuth2Swift: OAuth2Swift {
var codeVerifier: String?
override open func authorize(withCallbackURL url: URLConvertible, scope: String, state: String, codeChallenge: String, codeChallengeMethod: String = "S256", codeVerifier: String, parameters: Parameters = [:], headers: OAuthSwift.Headers? = nil, completionHandler completion: @escaping TokenCompletionHandler) -> OAuthSwiftRequestHandle? {
self.codeVerifier = codeVerifier
return super.authorize(
withCallbackURL:url,
scope: scope,
state: state,
codeChallenge: codeChallenge,
codeChallengeMethod: codeChallengeMethod,
codeVerifier: codeVerifier,
parameters: parameters,
headers: headers,
completionHandler: completion
)
}

override open func postOAuthAccessTokenWithRequestToken(byCode code: String, callbackURL: URL?, headers: OAuthSwift.Headers? = nil, completionHandler completion: @escaping TokenCompletionHandler) -> OAuthSwiftRequestHandle? {
var authorization_response = OAuthSwift.Parameters()
authorization_response["code"] = code
var parameters = OAuthSwift.Parameters()
if let codeVerifier = self.codeVerifier {
authorization_response["request"] = ["codeVerifier": codeVerifier]
}
parameters["authorization_response"] = authorization_response
completion(.success((self.client.credential, nil, parameters)))
return nil
}
}
/**
* Please read the Capacitor iOS Plugin Development Guide
* here: https://capacitorjs.com/docs/plugins/ios
Expand Down Expand Up @@ -62,7 +91,7 @@ public class GenericOAuth2Plugin: CAPPlugin {
static let ERR_USER_CANCELLED = "USER_CANCELLED"
}

var oauthSwift: OAuth2Swift?
var oauthSwift: MyOAuth2Swift?
var oauth2SafariDelegate: OAuth2SafariDelegate?
var handlerClasses = [String: OAuth2CustomHandler.Type]()
var handlerInstances = [String: OAuth2CustomHandler]()
Expand Down Expand Up @@ -123,7 +152,7 @@ public class GenericOAuth2Plugin: CAPPlugin {
return
}

let oauthSwift = OAuth2Swift(
let oauthSwift = MyOAuth2Swift(
consumerKey: appId,
consumerSecret: "", // never ever store the app secret on client!
authorizeUrl: "",
Expand Down Expand Up @@ -261,17 +290,17 @@ public class GenericOAuth2Plugin: CAPPlugin {
return
}

var oauthSwift: OAuth2Swift
var oauthSwift: MyOAuth2Swift
if let accessTokenEndpoint = getOverwritableString(call, PARAM_ACCESS_TOKEN_ENDPOINT), !accessTokenEndpoint.isEmpty {
oauthSwift = OAuth2Swift(
oauthSwift = MyOAuth2Swift(
consumerKey: appId,
consumerSecret: "", // never ever store the app secret on client!
authorizeUrl: baseUrl,
accessTokenUrl: accessTokenEndpoint,
responseType: responseType
)
} else {
oauthSwift = OAuth2Swift(
oauthSwift = MyOAuth2Swift(
consumerKey: appId,
consumerSecret: "", // never ever store the app secret on client!
authorizeUrl: baseUrl,
Expand Down