Skip to content
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

Added connection scopes to web auth #96

Merged
merged 4 commits into from
Mar 5, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Auth0.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
5B25A5321E3F68FA00563AE5 /* SafariSession.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SafariSession.swift; path = Auth0/SafariSession.swift; sourceTree = SOURCE_ROOT; };
5B6269E51E3F700000305093 /* NativeAuthSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NativeAuthSpec.swift; path = Auth0Tests/NativeAuthSpec.swift; sourceTree = SOURCE_ROOT; };
5B6269E91E3F9E5200305093 /* AuthProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AuthProvider.swift; path = Auth0/AuthProvider.swift; sourceTree = SOURCE_ROOT; };
5B9A54411E49E3AE004B5454 /* Auth0.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Auth0.plist; sourceTree = SOURCE_ROOT; };
5BD4A9CD1DEC6EFA00D6D7AE /* ResponseType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ResponseType.swift; path = Auth0/ResponseType.swift; sourceTree = SOURCE_ROOT; };
5F049B6C1CB42C29006F6C05 /* Auth0.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Auth0.h; path = Auth0/Auth0.h; sourceTree = "<group>"; };
5F049B6E1CB42C29006F6C05 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Auth0/Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -618,6 +619,7 @@
5F3965C81CF67DD800CDE7C0 /* App */ = {
isa = PBXGroup;
children = (
5B9A54411E49E3AE004B5454 /* Auth0.plist */,
5F3965C91CF67DD800CDE7C0 /* AppDelegate.swift */,
5F3965D01CF67DD800CDE7C0 /* Assets.xcassets */,
5F3965D51CF67DD800CDE7C0 /* Info.plist */,
Expand Down
5 changes: 5 additions & 0 deletions Auth0/SafariWebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class SafariWebAuth: WebAuth {
return self
}

func connectionScope(_ connectionScope: String) -> Self {
self.parameters["connection_scope"] = connectionScope
return self
}

func state(_ state: String) -> Self {
self.parameters["state"] = state
return self
Expand Down
9 changes: 9 additions & 0 deletions Auth0/WebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public protocol WebAuth: Trackable, Loggable {
*/
func scope(_ scope: String) -> Self

/**
Provider scopes for oauth2/social connections. e.g. Facebook, Google etc

- parameter connectionScope: oauth2/social comma separated scope list: `user_friends,email`

- returns: the same WebAuth instance to allow method chaining
*/
func connectionScope(_ connectionScope: String) -> Self

/**
State value that will be echoed after authentication
in order to check that the response is from your request and not other.
Expand Down
23 changes: 23 additions & 0 deletions Auth0Tests/WebAuthSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ class WebAuthSpec: QuickSpec {
"query": defaultQuery(withParameters: ["audience": "https://domain.auth0.com"]),
]
}

itBehavesLike(ValidAuthorizeURLExample) {
return [
"url": newWebAuth()
.connectionScope("user_friends,email")
.buildAuthorizeURL(withRedirectURL: RedirectURL, defaults: defaults, state: "state"),
"domain": Domain,
"query": defaultQuery(withParameters: ["connection_scope": "user_friends,email"]),
]
}

itBehavesLike(ValidAuthorizeURLExample) {
var newDefaults = defaults
newDefaults["connection_scope"] = "email"
return [
"url": newWebAuth()
.connectionScope("user_friends")
.buildAuthorizeURL(withRedirectURL: RedirectURL, defaults: newDefaults, state: "state"),
"domain": Domain,
"query": defaultQuery(withParameters: ["connection_scope": "user_friends"]),
]
}

}

describe("redirect uri") {
Expand Down