@@ -12,12 +12,12 @@ protocol PennAuthRequestable {}
1212
1313extension PennAuthRequestable {
1414
15- private var loginUrl : String {
16- return " https://weblogin.pennkey.upenn.edu/login "
15+ private var baseUrl : String {
16+ return " https://weblogin.pennkey.upenn.edu "
1717 }
1818
1919 private var authUrl : String {
20- return " https://idp .pennkey.upenn.edu/idp/Authn "
20+ return " https://weblogin .pennkey.upenn.edu/idp/profile "
2121 }
2222
2323 func makeAuthRequest( targetUrl: String , shibbolethUrl: String , _ completionHandler: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
@@ -51,20 +51,12 @@ extension PennAuthRequestable {
5151 }
5252
5353 private func makeRequestWithAuth( targetUrl: String , shibbolethUrl: String , html: String , _ completionHandler: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
54- guard let passcode = html. getMatches ( for: " name= \" passcode \" value= \" (.*?) \" " ) . first,
55- let required = html. getMatches ( for: " name= \" required \" value= \" (.*?) \" " ) . first,
56- let appfactor = html. getMatches ( for: " name= \" appfactor \" value= \" (.*?) \" " ) . first,
57- let ref = html. getMatches ( for: " name= \" ref \" value= \" (.*?) \" " ) . first,
58- let service = html. getMatches ( for: " name= \" service \" value= \" (.*?) \" " ) . first else {
59- UserDefaults . standard. setShibbolethAuth ( authedIn: false )
60- completionHandler ( nil , nil , NetworkingError . authenticationError)
61- return
54+ guard let actionUrl = html. getMatches ( for: " form action= \" (.*?) \" method= \" POST \" id= \" login-form \" " ) . first else {
55+ UserDefaults . standard. setShibbolethAuth ( authedIn: false )
56+ completionHandler ( nil , nil , NetworkingError . authenticationError)
57+ return
6258 }
6359
64- // Check if have two factor trusted browser cookie (may have expired)
65- // let cookies = HTTPCookieStorage.shared.cookies ?? []
66- let isTwoFactorTrusted = true //!cookies.filter { $0.name == "twoFactorTrustedBrowser" }.isEmpty
67-
6860 let genericPwdQueryable =
6961 GenericPasswordQueryable ( service: " PennWebLogin " )
7062 let secureStore =
@@ -84,30 +76,22 @@ extension PennAuthRequestable {
8476 pennkey = nil
8577 }
8678
87- guard pennkey != nil && password != nil && isTwoFactorTrusted else {
79+ guard pennkey != nil && password != nil else {
8880 UserDefaults . standard. setShibbolethAuth ( authedIn: false )
8981 completionHandler ( nil , nil , NetworkingError . authenticationError)
9082 return
9183 }
9284
93- let url = URL ( string: loginUrl ) !
85+ let url = URL ( string: baseUrl + actionUrl ) !
9486 var request = URLRequest ( url: url)
9587 request. httpMethod = " POST "
9688
97- var params : [ String : String ] = [
98- " password " : password,
99- " submit1 " : " Log in " ,
100- " passcode " : passcode,
101- " required " : required,
102- " appfactor " : appfactor,
103- " ref " : ref,
104- " service " : service,
105- " login " : pennkey,
89+ let params : [ String : String ] = [
90+ " j_username " : pennkey,
91+ " j_password " : password,
92+ " _eventId_proceed " : " " ,
10693 ]
10794
108- if let reauth = html. getMatches ( for: " name= \" reauth \" value= \" (.*?) \" " ) . first {
109- params [ " reauth " ] = reauth
110- }
11195 request. setValue ( " application/x-www-form-urlencoded " , forHTTPHeaderField: " Content-Type " )
11296 let characterSet = CharacterSet ( charactersIn: " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 " )
11397 let parameterArray = params. map { key, value -> String in
@@ -133,7 +117,6 @@ extension PennAuthRequestable {
133117 private func makeRequestWithShibboleth( targetUrl: String , shibbolethUrl: String , html: String , _ completionHandler: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
134118 guard let samlResponse = html. getMatches ( for: " <input type= \" hidden \" name= \" SAMLResponse \" value= \" (.*?) \" /> " ) . first,
135119 let relayState = html. getMatches ( for: " <input type= \" hidden \" name= \" RelayState \" value= \" (.*?) \" /> " ) . first? . replacingOccurrences ( of: " : " , with: " : " ) else {
136- HTTPCookieStorage . shared. removeCookies ( since: Date ( timeIntervalSince1970: 0 ) )
137120 UserDefaults . standard. setShibbolethAuth ( authedIn: false )
138121 completionHandler ( nil , nil , NetworkingError . authenticationError)
139122 return
0 commit comments