File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
WooCommerce/Classes/Extensions Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 11import Alamofire
22import Foundation
33import WebKit
4+ import WordPressAuthenticator
45import struct Yosemite. Credentials
56import class Networking. UserAgent
67
78/// An extension to authenticate WPCom automatically
89///
910extension WKWebView {
11+ static let wporgNoncePath = " /admin-ajax.php?action=rest-nonce "
12+
13+ func authenticateForWPOrg( with credentials: WordPressOrgCredentials ) throws -> URLRequest {
14+ var request = try URLRequest ( url: credentials. loginURL. asURL ( ) , method: . post)
15+ request. httpShouldHandleCookies = true
16+
17+ let redirectLink = ( credentials. adminURL + Self. wporgNoncePath)
18+ . addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed)
19+
20+ let parameters = [ " log " : credentials. username,
21+ " pwd " : credentials. password,
22+ " redirect_to " : redirectLink ?? " " ]
23+
24+ return try URLEncoding . default. encode ( request, with: parameters)
25+ }
26+
1027 func authenticateForWPComAndRedirect( to url: URL , credentials: Credentials ? ) {
1128 customUserAgent = UserAgent . defaultUserAgent
1229 do {
You can’t perform that action at this time.
0 commit comments