Skip to content

Commit 0bb1dfb

Browse files
committed
adding LocalAuthConfig and oAuthRedirecter
1 parent fe533db commit 0bb1dfb

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// LocalAuthConfig.swift
3+
// LocalAuthentication
4+
//
5+
// Created by Jonathan Guthrie on 2017-07-14.
6+
//
7+
8+
public struct LocalAuthConfig {
9+
public static var OAuthAppNameScheme = "oauth-swift://oauth-callback/"
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// JSONHandler.oauthRedirecter.swift
3+
// LocalAuthentication
4+
//
5+
// Created by Jonathan Guthrie on 2017-07-14.
6+
//
7+
8+
import PerfectHTTP
9+
import PerfectHTTPServer
10+
11+
12+
extension LocalAuthJSONHandlers {
13+
14+
/// Helps with OAuth2 redirection for iOS apps
15+
public static func oAuthRedirecter(data: [String:Any]) throws -> RequestHandler {
16+
return {
17+
request, response in
18+
var str = [String]()
19+
for param in request.params() {
20+
str.append("\(param.0)=\(param.1)")
21+
}
22+
response.status = .movedPermanently
23+
response.setHeader(.location, value: "\(LocalAuthConfig.OAuthAppNameScheme)?\(str.joined(separator: "&"))")
24+
response.completed()
25+
}
26+
}
27+
}
28+

0 commit comments

Comments
 (0)