Skip to content

Commit

Permalink
Adress Sessions and Documentation Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nidal-stytch committed Sep 6, 2024
1 parent a7ea3e9 commit 6d17dbf
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 274 deletions.
75 changes: 10 additions & 65 deletions Sources/StytchCore/Documentation.docc/StytchCore.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,85 +36,30 @@ Product | Methods | Delivery mechanisms
``StytchB2BClient/Members`` | ``StytchB2BClient/Members/getSync()``, ``StytchB2BClient/Members/get()-7fdhf`` | N/A
``StytchB2BClient/Organizations`` | ``StytchB2BClient/Organizations/getSync()``, ``StytchB2BClient/Organizations/get()-2esfw`` | N/A

### Async Options

Async functions are available via various mechanisms (Async/Await, Combine, callbacks) so you can use whatever best suits your needs.

### Configuration

Prior to using any authentication methods, you must configure the StytchClient/StytchB2BClient via one of two techniques:
1. Programmatically using the static ``StytchClient/configure(publicToken:hostUrl:)`` (consumer) or ``StytchB2BClient/configure(publicToken:hostUrl:)`` (B2B) functions.
1. Automatically, by including a `StytchConfiguration.plist` file in your main app bundle ([example](https://github.com/stytchauth/stytch-ios/blob/main/Stytch/Client/Shared/StytchConfiguration.plist))

### Usage

With just a few lines of code, you can easily authenticate your users and get back to focusing on the core of your product.

``` swift
import StytchCore
// When a user has entered their email and requests a magic link
_ = try await StytchClient.magicLinks.email.loginOrCreate(
parameters: .init(email: userEmail)
)
// Handling the deeplink in your SwiftUI App file (similar for AppDelegate)
YourContentView().onOpenUrl { url in
switch try await StytchClient.handle(url: url) {
// Your handling code
}
}
```

## Topics

### Consumer

- ``StytchClient``
- ``Session``
- ``User``
- ``AuthenticateResponseData``

### B2B

- ``StytchB2BClient``
- ``Organization``
- ``MemberSession``
- ``Member``

### Sessions

- ``Sessions``
- ``SessionToken``

### Authenticate Response Types
- ``AuthenticateResponse``
- ``AuthenticateResponseType``
- ``AuthenticateResponseDataType``
- ``AuthenticateResponseData``
- ``B2BAuthenticateResponse``
- ``B2BAuthenticateResponseType``
- ``B2BAuthenticateResponseDataType``
- ``B2BAuthenticateResponseData``
- ``B2BMFAAuthenticateResponseData``

### Generic Response Types
### Common

- ``BasicResponseType``
- ``BasicResponse``
- ``Response``

### Error Types
- ``StytchError``

### Deeplink Types

- ``DeeplinkHandledStatus``

### Additional Types

- ``AuthenticationFactor``
- ``SSORegistration``
- ``Identifier``
- ``Completion``
- ``Minutes``
- ``EmptyCodable``
- ``JSON``
- ``Union``
- ``UserResponse``
- ``SessionToken``
- ``SessionTokens``
- ``RBACPolicy`
- ``Response`
- ``StytchError`
- ``StytchAPIError`
- ``PKCECodePair`
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import Combine
import Foundation

public extension StytchB2BClientSessions {
public extension StytchB2BClient.StytchB2BClientSessions {
/// Wraps Stytch's [authenticate](https://stytch.com/docs/api/session-auth) Session endpoint and validates that the session issued to the user is still valid, returning both an opaque sessionToken and sessionJwt for this session. The sessionJwt will have a fixed lifetime of five minutes regardless of the underlying session duration, though it will be refreshed automatically in the background after a successful authentication.
func authenticate(parameters: Sessions.AuthenticateParameters, completion: @escaping Completion<B2BAuthenticateResponse>) {
func authenticate(parameters: AuthenticateParameters, completion: @escaping Completion<B2BAuthenticateResponse>) {
Task {
do {
completion(.success(try await authenticate(parameters: parameters)))
Expand All @@ -16,7 +16,7 @@ public extension StytchB2BClientSessions {
}

/// Wraps Stytch's [authenticate](https://stytch.com/docs/api/session-auth) Session endpoint and validates that the session issued to the user is still valid, returning both an opaque sessionToken and sessionJwt for this session. The sessionJwt will have a fixed lifetime of five minutes regardless of the underlying session duration, though it will be refreshed automatically in the background after a successful authentication.
func authenticate(parameters: Sessions.AuthenticateParameters) -> AnyPublisher<B2BAuthenticateResponse, Error> {
func authenticate(parameters: AuthenticateParameters) -> AnyPublisher<B2BAuthenticateResponse, Error> {
return Deferred {
Future({ promise in
Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Combine
import Foundation

public extension StytchB2BClientSessions {
public extension StytchB2BClient.StytchB2BClientSessions {
/// Use this endpoint to exchange a Member's existing session for another session in a different Organization.
func exchange(parameters: ExchangeParameters, completion: @escaping Completion<B2BMFAAuthenticateResponse>) {
Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import Combine
import Foundation

public extension StytchB2BClientSessions {
public extension StytchB2BClient.StytchB2BClientSessions {
/// Wraps Stytch's [revoke](https://stytch.com/docs/api/session-revoke) Session endpoint and revokes the user's current session. This method should be used to log out a user. A successful revocation will terminate session-refresh polling.
func revoke(parameters: Sessions.RevokeParameters = .init(), completion: @escaping Completion<BasicResponse>) {
func revoke(parameters: RevokeParameters = .init(), completion: @escaping Completion<BasicResponse>) {
Task {
do {
completion(.success(try await revoke(parameters: parameters)))
Expand All @@ -16,7 +16,7 @@ public extension StytchB2BClientSessions {
}

/// Wraps Stytch's [revoke](https://stytch.com/docs/api/session-revoke) Session endpoint and revokes the user's current session. This method should be used to log out a user. A successful revocation will terminate session-refresh polling.
func revoke(parameters: Sessions.RevokeParameters = .init()) -> AnyPublisher<BasicResponse, Error> {
func revoke(parameters: RevokeParameters = .init()) -> AnyPublisher<BasicResponse, Error> {
return Deferred {
Future({ promise in
Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import Combine
import Foundation

public extension StytchClientSessions {
public extension StytchClient.StytchClientSessions {
/// Wraps Stytch's [authenticate](https://stytch.com/docs/api/session-auth) Session endpoint and validates that the session issued to the user is still valid, returning both an opaque sessionToken and sessionJwt for this session. The sessionJwt will have a fixed lifetime of five minutes regardless of the underlying session duration, though it will be refreshed automatically in the background after a successful authentication.
func authenticate(parameters: Sessions.AuthenticateParameters, completion: @escaping Completion<AuthenticateResponse>) {
func authenticate(parameters: AuthenticateParameters, completion: @escaping Completion<AuthenticateResponse>) {
Task {
do {
completion(.success(try await authenticate(parameters: parameters)))
Expand All @@ -16,7 +16,7 @@ public extension StytchClientSessions {
}

/// Wraps Stytch's [authenticate](https://stytch.com/docs/api/session-auth) Session endpoint and validates that the session issued to the user is still valid, returning both an opaque sessionToken and sessionJwt for this session. The sessionJwt will have a fixed lifetime of five minutes regardless of the underlying session duration, though it will be refreshed automatically in the background after a successful authentication.
func authenticate(parameters: Sessions.AuthenticateParameters) -> AnyPublisher<AuthenticateResponse, Error> {
func authenticate(parameters: AuthenticateParameters) -> AnyPublisher<AuthenticateResponse, Error> {
return Deferred {
Future({ promise in
Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import Combine
import Foundation

public extension StytchClientSessions {
public extension StytchClient.StytchClientSessions {
/// Wraps Stytch's [revoke](https://stytch.com/docs/api/session-revoke) Session endpoint and revokes the user's current session. This method should be used to log out a user. A successful revocation will terminate session-refresh polling.
func revoke(parameters: Sessions.RevokeParameters = .init(), completion: @escaping Completion<BasicResponse>) {
func revoke(parameters: RevokeParameters = .init(), completion: @escaping Completion<BasicResponse>) {
Task {
do {
completion(.success(try await revoke(parameters: parameters)))
Expand All @@ -16,7 +16,7 @@ public extension StytchClientSessions {
}

/// Wraps Stytch's [revoke](https://stytch.com/docs/api/session-revoke) Session endpoint and revokes the user's current session. This method should be used to log out a user. A successful revocation will terminate session-refresh polling.
func revoke(parameters: Sessions.RevokeParameters = .init()) -> AnyPublisher<BasicResponse, Error> {
func revoke(parameters: RevokeParameters = .init()) -> AnyPublisher<BasicResponse, Error> {
return Deferred {
Future({ promise in
Task {
Expand Down
89 changes: 0 additions & 89 deletions Sources/StytchCore/StytchB2BClient/StytchB2BClient+Sessions.swift

This file was deleted.

Loading

0 comments on commit 6d17dbf

Please sign in to comment.