Skip to content

Commit

Permalink
Merge pull request #47 from auth0/feauture-use-protocols
Browse files Browse the repository at this point in the history
Use protocols
  • Loading branch information
hzalaz authored Sep 15, 2016
2 parents 07de0f0 + 3c43f33 commit a347c2c
Show file tree
Hide file tree
Showing 16 changed files with 911 additions and 557 deletions.
42 changes: 41 additions & 1 deletion Auth0.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
5FADB60D1CED7E0800D4BB50 /* UserPatchAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FADB60B1CED7E0800D4BB50 /* UserPatchAttributes.swift */; };
5FADB60F1CED7E5200D4BB50 /* UserPatchAttributesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FADB60E1CED7E5200D4BB50 /* UserPatchAttributesSpec.swift */; };
5FADB6101CED7E5200D4BB50 /* UserPatchAttributesSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FADB60E1CED7E5200D4BB50 /* UserPatchAttributesSpec.swift */; };
5FAE9C911D8878D400A871CE /* SafariWebAuth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FAE9C901D8878D400A871CE /* SafariWebAuth.swift */; };
5FAE9C931D88AA2D00A871CE /* Auth0Authentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FAE9C921D88AA2D00A871CE /* Auth0Authentication.swift */; };
5FAE9C941D88AA2D00A871CE /* Auth0Authentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FAE9C921D88AA2D00A871CE /* Auth0Authentication.swift */; };
5FAE9C951D88AA2D00A871CE /* Auth0Authentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FAE9C921D88AA2D00A871CE /* Auth0Authentication.swift */; };
5FAE9C961D88AA2D00A871CE /* Auth0Authentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FAE9C921D88AA2D00A871CE /* Auth0Authentication.swift */; };
5FBBF0381CC964BC0024D2AF /* Matchers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBBF0371CC964BC0024D2AF /* Matchers.swift */; };
5FBBF0391CC964BC0024D2AF /* Matchers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBBF0371CC964BC0024D2AF /* Matchers.swift */; };
5FBBF03B1CC96AA70024D2AF /* Responses.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBBF03A1CC96AA70024D2AF /* Responses.swift */; };
Expand Down Expand Up @@ -337,6 +342,17 @@
5FADB6081CED500900D4BB50 /* ManagementSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagementSpec.swift; sourceTree = "<group>"; };
5FADB60B1CED7E0800D4BB50 /* UserPatchAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserPatchAttributes.swift; sourceTree = "<group>"; };
5FADB60E1CED7E5200D4BB50 /* UserPatchAttributesSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserPatchAttributesSpec.swift; sourceTree = "<group>"; };
5FAE9C871D88731500A871CE /* Cartfile.resolved */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile.resolved; sourceTree = "<group>"; };
5FAE9C881D88731500A871CE /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
5FAE9C891D88731500A871CE /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
5FAE9C8A1D88731500A871CE /* Gemfile.lock */ = {isa = PBXFileReference; lastKnownFileType = text; path = Gemfile.lock; sourceTree = "<group>"; };
5FAE9C8B1D88731500A871CE /* Gemfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Gemfile; sourceTree = "<group>"; };
5FAE9C8C1D88731500A871CE /* Auth0.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = Auth0.podspec; sourceTree = "<group>"; };
5FAE9C8D1D88731500A871CE /* codecov.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = codecov.yml; sourceTree = "<group>"; };
5FAE9C8E1D88731500A871CE /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
5FAE9C8F1D88731500A871CE /* Cartfile.private */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile.private; sourceTree = "<group>"; };
5FAE9C901D8878D400A871CE /* SafariWebAuth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SafariWebAuth.swift; sourceTree = "<group>"; };
5FAE9C921D88AA2D00A871CE /* Auth0Authentication.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Auth0Authentication.swift; sourceTree = "<group>"; };
5FBBF0371CC964BC0024D2AF /* Matchers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Matchers.swift; sourceTree = "<group>"; };
5FBBF03A1CC96AA70024D2AF /* Responses.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Responses.swift; sourceTree = "<group>"; };
5FBBF03E1CCA8FF40024D2AF /* Authentication.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Authentication.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -452,11 +468,12 @@
5F049B5F1CB42C29006F6C05 = {
isa = PBXGroup;
children = (
5F3965C81CF67DD800CDE7C0 /* App */,
5F049B6B1CB42C29006F6C05 /* Auth0 */,
5F06DD921CC451430011842B /* Auth0Tests */,
5F3965C81CF67DD800CDE7C0 /* App */,
5F06DDC21CC5712F0011842B /* Frameworks */,
5F049B6A1CB42C29006F6C05 /* Products */,
5FAE9C861D8872E900A871CE /* Supporting Files */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -573,6 +590,7 @@
5FCAB1751D0900CF00331C84 /* SessionStorage.swift */,
5F3965C11CF67CF000CDE7C0 /* WebAuth.swift */,
5FD255B91D14F70B00387ECB /* WebAuthError.swift */,
5FAE9C901D8878D400A871CE /* SafariWebAuth.swift */,
);
path = WebAuth;
sourceTree = "<group>";
Expand Down Expand Up @@ -609,6 +627,22 @@
path = Management;
sourceTree = "<group>";
};
5FAE9C861D8872E900A871CE /* Supporting Files */ = {
isa = PBXGroup;
children = (
5FAE9C871D88731500A871CE /* Cartfile.resolved */,
5FAE9C8F1D88731500A871CE /* Cartfile.private */,
5FAE9C881D88731500A871CE /* CHANGELOG.md */,
5FAE9C891D88731500A871CE /* README.md */,
5FAE9C8A1D88731500A871CE /* Gemfile.lock */,
5FAE9C8B1D88731500A871CE /* Gemfile */,
5FAE9C8C1D88731500A871CE /* Auth0.podspec */,
5FAE9C8D1D88731500A871CE /* codecov.yml */,
5FAE9C8E1D88731500A871CE /* LICENSE */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
5FBBF0331CC95FA40024D2AF /* Utils */ = {
isa = PBXGroup;
children = (
Expand All @@ -628,6 +662,7 @@
5F74CB3C1CEE8E9100226823 /* Identity.swift */,
5FE2F8C21CD1498E003628F4 /* Profile.swift */,
5FD255AD1D14A4A300387ECB /* AuthenticationError.swift */,
5FAE9C921D88AA2D00A871CE /* Auth0Authentication.swift */,
);
path = Authentication;
sourceTree = "<group>";
Expand Down Expand Up @@ -1129,6 +1164,7 @@
5FCAB1731D09009600331C84 /* NSData+URLSafe.swift in Sources */,
5FE686A61D188DEF0075874C /* Telemetry.swift in Sources */,
5FD255BA1D14F70B00387ECB /* WebAuthError.swift in Sources */,
5FAE9C931D88AA2D00A871CE /* Auth0Authentication.swift in Sources */,
5FD255B71D14F00900387ECB /* Auth0Error.swift in Sources */,
5FD255AE1D14A4A300387ECB /* AuthenticationError.swift in Sources */,
5F06DDC91CC66B710011842B /* Auth0.swift in Sources */,
Expand All @@ -1145,6 +1181,7 @@
5F3965C21CF67CF000CDE7C0 /* WebAuth.swift in Sources */,
5FCAB1761D0900CF00331C84 /* SessionStorage.swift in Sources */,
5FE2F8C31CD1498E003628F4 /* Profile.swift in Sources */,
5FAE9C911D8878D400A871CE /* SafariWebAuth.swift in Sources */,
5FCCC3151CF4DB4400901E2E /* NSError+Authentication.swift in Sources */,
5FBBF03F1CCA8FF40024D2AF /* Authentication.swift in Sources */,
5FADB6061CED27FB00D4BB50 /* Users.swift in Sources */,
Expand All @@ -1165,6 +1202,7 @@
5FF465BD1CE2AC4500F7ED8C /* Management.swift in Sources */,
5F23E6EF1D4B872000C3F2D9 /* A0ChallengeGenerator.m in Sources */,
5F06DDCA1CC66B710011842B /* Auth0.swift in Sources */,
5FAE9C941D88AA2D00A871CE /* Auth0Authentication.swift in Sources */,
5FD255B81D14F00900387ECB /* Auth0Error.swift in Sources */,
5FD255B51D14DD2600387ECB /* ManagementError.swift in Sources */,
5FE2F8B31CCEAED8003628F4 /* Requestable.swift in Sources */,
Expand Down Expand Up @@ -1255,6 +1293,7 @@
5F23E6D51D4ACD4C00C3F2D9 /* Telemetry.swift in Sources */,
5F23E6E11D4ACD7F00C3F2D9 /* UserPatchAttributes.swift in Sources */,
5F23E6DF1D4ACD7A00C3F2D9 /* Logger.swift in Sources */,
5FAE9C951D88AA2D00A871CE /* Auth0Authentication.swift in Sources */,
5F23E6D91D4ACD5B00C3F2D9 /* Identity.swift in Sources */,
5F23E6EC1D4ACDD200C3F2D9 /* A0ChallengeGenerator.m in Sources */,
5F23E6E21D4ACD7F00C3F2D9 /* Users.swift in Sources */,
Expand Down Expand Up @@ -1285,6 +1324,7 @@
5F23E6FF1D4B88D400C3F2D9 /* Telemetry.swift in Sources */,
5F23E70A1D4B88F600C3F2D9 /* UserPatchAttributes.swift in Sources */,
5F23E71B1D4B891E00C3F2D9 /* Auth0Error.swift in Sources */,
5FAE9C961D88AA2D00A871CE /* Auth0Authentication.swift in Sources */,
5F23E7081D4B88F000C3F2D9 /* Logger.swift in Sources */,
5F23E7031D4B88DB00C3F2D9 /* Identity.swift in Sources */,
5F23E70B1D4B88F600C3F2D9 /* Users.swift in Sources */,
Expand Down
59 changes: 3 additions & 56 deletions Auth0/Auth0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Foundation
- returns: Auth0 Authentication API
*/
public func authentication(clientId clientId: String, domain: String, session: NSURLSession = .sharedSession()) -> Authentication {
return Authentication(clientId: clientId, url: .a0_url(domain), session: session)
return Auth0Authentication(clientId: clientId, url: .a0_url(domain), session: session)
}

/**
Expand Down Expand Up @@ -72,59 +72,6 @@ public func authentication(session session: NSURLSession = .sharedSession(), bun
return authentication(clientId: values.clientId, domain: values.domain, session: session)
}

/**
Auth0 Management API v2 to perform CRUD operation against your Users, Clients, Connections, etc.

```
Auth0.management(token: token)
```

Auth0 domain is loaded from the file `Auth0.plist` in your main bundle with the following content:

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ClientId</key>
<string>{YOUR_CLIENT_ID}</string>
<key>Domain</key>
<string>{YOUR_DOMAIN}</string>
</dict>
</plist>
```

- parameter token: token of Management API v2 with the correct allowed scopes to perform the desired action
- parameter session: instance of NSURLSession used for networking. By default it will use the shared NSURLSession
- parameter bundle: bundle used to locate the `Auth0.plist` file. By default is the main bundle

- returns: Auth0 Management API v2
- important: Auth0.swift has yet to implement all endpoints. Now you can only perform some CRUD operations against Users
- important: Calling this method without a valid `Auth0.plist` will crash your application
*/
public func management(token token: String, session: NSURLSession = .sharedSession(), bundle: NSBundle = NSBundle.mainBundle()) -> Management {
let values = plistValues(bundle: bundle)!
return management(token: token, domain: values.domain, session: session)
}

/**
Auth0 Management API v2 to perform CRUD operation against your Users, Clients, Connections, etc.

```
Auth0.management(token: token, domain: "samples.auth0.com")
```

- parameter token: token of Management API v2 with the correct allowed scopes to perform the desired action
- parameter domain: domain of your Auth0 account. e.g.: 'samples.auth0.com'
- parameter session: instance of NSURLSession used for networking. By default it will use the shared NSURLSession

- returns: Auth0 Management API v2
- important: Auth0.swift has yet to implement all endpoints. Now you can only perform some CRUD operations against Users
*/
public func management(token token: String, domain: String, session: NSURLSession = .sharedSession()) -> Management {
return Management(token: token, url: .a0_url(domain), session: session)
}

/**
Auth0 Management Users API v2 that allows CRUD operations with the users endpoint.

Expand Down Expand Up @@ -187,7 +134,7 @@ public func users(token token: String, session: NSURLSession = .sharedSession(),
- returns: Auth0 Management API v2
*/
public func users(token token: String, domain: String, session: NSURLSession = .sharedSession()) -> Users {
return management(token: token, domain: domain, session: session).users()
return Management(token: token, url: .a0_url(domain), session: session)
}

func plistValues(bundle bundle: NSBundle) -> (clientId: String, domain: String)? {
Expand All @@ -208,4 +155,4 @@ func plistValues(bundle bundle: NSBundle) -> (clientId: String, domain: String)?
return nil
}
return (clientId: clientId, domain: domain)
}
}
Loading

0 comments on commit a347c2c

Please sign in to comment.