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

Native Authentication support #86

Merged
merged 5 commits into from
Jan 31, 2017
Merged

Conversation

cocojoe
Copy link
Member

@cocojoe cocojoe commented Jan 30, 2017

Adds support for native authentication with a third party IdP using their iOS SDK and then performing the Auth against Auth0.

@@ -21,9 +21,9 @@ Pod::Spec.new do |s|
s.ios.source_files = 'Auth0/*.{swift,h,m}'
s.ios.frameworks = 'UIKit', 'SafariServices'
s.osx.source_files = 'Auth0/*.swift'
s.osx.exclude_files = 'Auth0/_ObjectiveWebAuth.swift', 'Auth0/ControllerModalPresenter.swift', 'Auth0/OAuth2Grant.swift', 'Auth0/OAuth2Session.swift', 'Auth0/SessionStorage.swift', 'Auth0/WebAuth.swift', 'Auth0/WebAuthError.swift', 'Auth0/SafariWebAuth.swift'
s.osx.exclude_files = 'Auth0/_ObjectiveWebAuth.swift', 'Auth0/ControllerModalPresenter.swift', 'Auth0/OAuth2Grant.swift', 'Auth0/AuthTransaction.swift', 'Auth0/TransactionStore.swift', 'Auth0/WebAuth.swift', 'Auth0/WebAuthError.swift', 'Auth0/SafariWebAuth.swift'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we exclude native auth file?

import SafariServices

/**
Represents an on going AuthTransaction with Auth0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Represents an on going Auth transaction with an Identity Provider (Auth0 or a third party).

/**
Represents an on going AuthTransaction with Auth0.

It will handle result from the redirect URL configured when the AuthTransaction flow was started,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the Auth will be done outside the application control, Safari or third party IdP App, the only way to communicate the results back is using an url with a registered custom scheme in our application so iOS can open it on success/failure. When that happens iOS will call a method in your AppDelegate and there is where we need to handle the result.


import UIKit

public protocol AuthProvider {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs?

let token: String
let extras: [String: Any]

public init(token: String, extras: [String: Any]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make public the attributes instead of creating an init

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought I had did this for a reason, if you want a public structure type to be initializable with a memberwise initializer when used in another module, you must provide a public memberwise initializer yourself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless both attributes are public so it should infer the constructor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will infer for the project but not when imported. Source

nativeAuthCredentials.extras.forEach { key, value in parameters[key] = value }

authentication().loginSocial(token: nativeAuthCredentials.token, connection: connection, scope: scope, parameters: parameters)
.start { callback($0) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pass the callback as the parameter why wrapping it up in another one?

static let sharedInstance = SessionStorage()
/// Keeps track of current Auth Transaction
class TransactionStore {
static let sharedInstance = TransactionStore()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we are modifying it let's use the shared name instead

func login(withConnection connection: String, scope: String, parameters: [String: Any]) -> NativeAuthTransaction
}

public struct NativeAuthCredentials {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs?

func auth(callback: @escaping Callback) -> ()
}

public extension NativeAuthTransaction {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc?

@@ -0,0 +1,74 @@
// NativeAuth.swift
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we might need to split the file in parts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I broke out AuthProvider, everything left is NativeAuth*

Scope, connnection and parameters are used in the final stage of Auth Transaction during the Auth0 Social Authentication.

```
class SocialNativeTransaction: NativeAuthTransaction {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not buying this example, it does not explain what each method does and what the parameter are for, what are the properties. Also it is not showing any real case usage.

We need to document each protocol property and method explaining what it does

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have fleshed this out, let's see how it feels.

@hzalaz hzalaz force-pushed the api_add_native_authentication branch from e14787f to 03805e1 Compare January 30, 2017 21:17
@cocojoe cocojoe force-pushed the api_add_native_authentication branch from 03805e1 to 1fc08ca Compare January 30, 2017 21:31
cocojoe and others added 3 commits January 30, 2017 19:43
Rename SessionStorage to TransactionStore, implements AuthStorage
Rename OAuth2Session to AuthTransaction Update tests
Separate AuthTransaction / SafariSession code
Remove session references in TransactionStore
@hzalaz hzalaz force-pushed the api_add_native_authentication branch from 1fc08ca to 33e7482 Compare January 30, 2017 22:43
@cocojoe cocojoe force-pushed the api_add_native_authentication branch from 2b7b65a to 1c7d306 Compare January 31, 2017 13:17
@hzalaz hzalaz added this to the v1-Next milestone Jan 31, 2017
@hzalaz hzalaz changed the title API Native Authentication Protocols Native Authentication support Jan 31, 2017
@hzalaz hzalaz merged commit f3b1b12 into master Jan 31, 2017
@hzalaz hzalaz deleted the api_add_native_authentication branch January 31, 2017 16:12
@hzalaz hzalaz modified the milestones: v1-Next, 1.2.0 Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants