mirror of
https://github.com/logto-io/logto.git
synced 2025-03-10 22:22:45 -05:00
docs: add Swift Logto client reference (#574)
* docs: add Swift Logto client reference * docs: adjust position
This commit is contained in:
parent
3dedbe4cac
commit
dc2a6ac961
34 changed files with 636 additions and 2 deletions
|
@ -1 +1 @@
|
|||
# Overview
|
||||
# SDK Reference Overview
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
---
|
||||
sidebar_position: 3.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoErrors.Response`
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
---
|
||||
sidebar_position: 3.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoErrors.UriVerification`
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
---
|
||||
sidebar_position: 3.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoErrors.UrlConstruction`
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
---
|
||||
sidebar_position: 4.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoRequest.HttpMethod`
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
---
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoRequest`
|
||||
|
|
164
packages/docs/docs/sdk/Swift/LogtoClient/Classes/LogtoClient.md
Normal file
164
packages/docs/docs/sdk/Swift/LogtoClient/Classes/LogtoClient.md
Normal file
|
@ -0,0 +1,164 @@
|
|||
**CLASS**
|
||||
|
||||
# `LogtoClient`
|
||||
|
||||
```swift
|
||||
public class LogtoClient
|
||||
```
|
||||
|
||||
## Structs
|
||||
|
||||
### [NotificationObject](../Structs/LogtoClient.NotificationObject.md)
|
||||
|
||||
## Properties
|
||||
### `HandleNotification`
|
||||
|
||||
```swift
|
||||
public static let HandleNotification = Notification.Name("Logto Handle")
|
||||
```
|
||||
|
||||
The notification name for LogtoClient to handle.
|
||||
|
||||
### `idToken`
|
||||
|
||||
```swift
|
||||
public internal(set) var idToken: String?
|
||||
```
|
||||
|
||||
The cached ID Token in raw string.
|
||||
Use `.getIdTokenClaims()` to retrieve structured data.
|
||||
|
||||
### `refreshToken`
|
||||
|
||||
```swift
|
||||
public internal(set) var refreshToken: String?
|
||||
```
|
||||
|
||||
The cached Refresh Token.
|
||||
|
||||
### `oidcConfig`
|
||||
|
||||
```swift
|
||||
public internal(set) var oidcConfig: LogtoCore.OidcConfigResponse?
|
||||
```
|
||||
|
||||
The config fetched from [OIDC Discovery](https://openid.net/specs/openid-connect-discovery-1_0.html) endpoint.
|
||||
|
||||
### `isAuthenticated`
|
||||
|
||||
```swift
|
||||
public var isAuthenticated: Bool
|
||||
```
|
||||
|
||||
Whether the user has been authenticated.
|
||||
|
||||
## Methods
|
||||
### `handle(forClientId:url:)`
|
||||
|
||||
```swift
|
||||
public static func handle(forClientId clientId: String? = nil, url: URL)
|
||||
```
|
||||
|
||||
Post a notification that tells Logto clients to handle the given URL.
|
||||
|
||||
Usually this function need to be called in `onOpenURL(perform:)` in SwiftUI or `application(_:open:options:)` in AppDelegate. See integration guide for detailed information.
|
||||
|
||||
- Parameters:
|
||||
- forClientId: If the notification is for specific client ID only. When `nil`, all Logto clients will try to handle the notification.
|
||||
- url:The URL that needs to be handled.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Description |
|
||||
| ---- | ----------- |
|
||||
| forClientId | If the notification is for specific client ID only. When `nil`, all Logto clients will try to handle the notification. |
|
||||
| url | The URL that needs to be handled. |
|
||||
|
||||
### `init(useConfig:socialPlugins:session:)`
|
||||
|
||||
```swift
|
||||
public init(
|
||||
useConfig config: LogtoConfig,
|
||||
socialPlugins: [LogtoSocialPlugin] = [],
|
||||
session: NetworkSession = URLSession.shared
|
||||
)
|
||||
```
|
||||
|
||||
### `signInWithBrowser(redirectUri:)`
|
||||
|
||||
```swift
|
||||
public func signInWithBrowser(
|
||||
redirectUri: String
|
||||
) async throws
|
||||
```
|
||||
|
||||
Start a sign in session with WKWebView. If the function returns with no error threw, it means the user has signed in successfully.
|
||||
|
||||
- Parameters:
|
||||
- redirectUri: One of Redirect URIs of this application.
|
||||
- Throws: An error if the session failed to complete.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Description |
|
||||
| ---- | ----------- |
|
||||
| redirectUri | One of Redirect URIs of this application. |
|
||||
|
||||
### `signOut()`
|
||||
|
||||
```swift
|
||||
func signOut() async -> Errors.SignOut?
|
||||
```
|
||||
|
||||
Clear all tokens in memory and Keychain. Also try to revoke the Refresh Token from the OIDC provider.
|
||||
|
||||
- Returns: An error if failed to revoke the token. Usually the error is safe to ignore.
|
||||
|
||||
### `getAccessToken(for:)`
|
||||
|
||||
```swift
|
||||
@MainActor public func getAccessToken(for resource: String?) async throws -> String
|
||||
```
|
||||
|
||||
Get access token for the given resrouce. If resource is `nil`, return the access token for user endpoint.
|
||||
|
||||
If the cached access token has expired, this function will try to use `refreshToken` to fetch a new access token from the OIDC provider.
|
||||
|
||||
- Parameters:
|
||||
- resource: The resource indicator.
|
||||
- Throws: An error if failed to get a valid access token.
|
||||
- Returns: Access token in string.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Description |
|
||||
| ---- | ----------- |
|
||||
| resource | The resource indicator. |
|
||||
|
||||
### `fetchUserInfo()`
|
||||
|
||||
```swift
|
||||
public func fetchUserInfo() async throws -> LogtoCore.UserInfoResponse
|
||||
```
|
||||
|
||||
### `getIdTokenClaims()`
|
||||
|
||||
```swift
|
||||
public func getIdTokenClaims() throws -> IdTokenClaims
|
||||
```
|
||||
|
||||
Get structured [ID Token Claims](https://openid.net/specs/openid-connect-core-1_0.html#IDToken).
|
||||
- Throws: An error if no ID Token presents or decode token failed.
|
||||
|
||||
### `handle(url:)`
|
||||
|
||||
```swift
|
||||
public func handle(url: URL) -> Bool
|
||||
```
|
||||
|
||||
Try to handle the given URL by iterating all social plugins.
|
||||
|
||||
The iteration stops when one of the social plugins handled the URL.
|
||||
|
||||
- Returns: `true` if one of the social plugins handled this URL.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"position": 1
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
sidebar_position: 1.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrorTypes.AccessToken`
|
||||
|
||||
```swift
|
||||
public enum AccessToken
|
||||
```
|
||||
|
||||
## Cases
|
||||
### `noRefreshTokenFound`
|
||||
|
||||
```swift
|
||||
case noRefreshTokenFound
|
||||
```
|
||||
|
||||
No Refresh Token presents in the Keychain.
|
||||
|
||||
### `unableToFetchTokenByRefreshToken`
|
||||
|
||||
```swift
|
||||
case unableToFetchTokenByRefreshToken
|
||||
```
|
||||
|
||||
Unable to use Refresh Token to fetch a new Access Token.
|
||||
The Refresh Token could be expired or revoked.
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
sidebar_position: 1.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrorTypes.JwkSet`
|
||||
|
||||
```swift
|
||||
public enum JwkSet
|
||||
```
|
||||
|
||||
## Cases
|
||||
### `unableToFetchJwkSet`
|
||||
|
||||
```swift
|
||||
case unableToFetchJwkSet
|
||||
```
|
||||
|
||||
Unable to fetch JWK set from the given URI.
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
sidebar_position: 1.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrorTypes.OidcConfig`
|
||||
|
||||
```swift
|
||||
public enum OidcConfig
|
||||
```
|
||||
|
||||
## Cases
|
||||
### `unableToFetchOidcConfig`
|
||||
|
||||
```swift
|
||||
case unableToFetchOidcConfig
|
||||
```
|
||||
|
||||
Unable to fetch OIDC config from the OIDC provider.
|
|
@ -0,0 +1,60 @@
|
|||
---
|
||||
sidebar_position: 1.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrorTypes.SignIn`
|
||||
|
||||
```swift
|
||||
public enum SignIn: String
|
||||
```
|
||||
|
||||
## Cases
|
||||
### `unknownError`
|
||||
|
||||
```swift
|
||||
case unknownError
|
||||
```
|
||||
|
||||
### `authFailed`
|
||||
|
||||
```swift
|
||||
case authFailed
|
||||
```
|
||||
|
||||
Failed to complete the authentication.
|
||||
This could be an internal error or the user canceled the authentication.
|
||||
|
||||
### `unableToConstructRedirectUri`
|
||||
|
||||
```swift
|
||||
case unableToConstructRedirectUri
|
||||
```
|
||||
|
||||
Unable to construct Redirect URI for the given string.
|
||||
|
||||
### `unableToConstructAuthUri`
|
||||
|
||||
```swift
|
||||
case unableToConstructAuthUri
|
||||
```
|
||||
|
||||
Unable to construct Redirect URI for the config.
|
||||
Please double check OIDC and Logto config.
|
||||
|
||||
### `unableToFetchToken`
|
||||
|
||||
```swift
|
||||
case unableToFetchToken
|
||||
```
|
||||
|
||||
Unable to finish the initial token request after authentication.
|
||||
|
||||
### `unexpectedSignInCallback`
|
||||
|
||||
```swift
|
||||
case unexpectedSignInCallback
|
||||
```
|
||||
|
||||
The sign in callback URI is not valid.
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
sidebar_position: 1.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrorTypes.SignOut`
|
||||
|
||||
```swift
|
||||
public enum SignOut: String
|
||||
```
|
||||
|
||||
## Cases
|
||||
### `unableToRevokeToken`
|
||||
|
||||
```swift
|
||||
case unableToRevokeToken
|
||||
```
|
||||
|
||||
Unable to revoke token in the OIDC provider.
|
||||
Usually this error is safe to ignore.
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
sidebar_position: 1.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrorTypes.UserInfo`
|
||||
|
||||
```swift
|
||||
public enum UserInfo
|
||||
```
|
||||
|
||||
## Cases
|
||||
### `unableToFetchUserInfo`
|
||||
|
||||
```swift
|
||||
case unableToFetchUserInfo
|
||||
```
|
||||
|
||||
Unable to fetch user info from the OIDC provider.
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrorTypes`
|
||||
|
||||
```swift
|
||||
public enum LogtoClientErrorTypes
|
||||
```
|
||||
|
||||
## Enums
|
||||
|
||||
### [AccessToken](LogtoClientErrorTypes.AccessToken.md)
|
||||
### [JwkSet](LogtoClientErrorTypes.JwkSet.md)
|
||||
### [OidcConfig](LogtoClientErrorTypes.OidcConfig.md)
|
||||
### [SignIn](LogtoClientErrorTypes.SignIn.md)
|
||||
### [SignOut](LogtoClientErrorTypes.SignOut.md)
|
||||
### [UserInfo](LogtoClientErrorTypes.UserInfo.md)
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
sidebar_position: 2.1
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrors.IdToken`
|
||||
|
||||
```swift
|
||||
public enum IdToken: String, LocalizedError
|
||||
```
|
||||
|
||||
## Cases
|
||||
### `notAuthenticated`
|
||||
|
||||
```swift
|
||||
case notAuthenticated
|
||||
```
|
||||
|
||||
No ID Token presents in the Keychain.
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
**ENUM**
|
||||
|
||||
# `LogtoClientErrors`
|
||||
|
||||
```swift
|
||||
public enum LogtoClientErrors
|
||||
```
|
||||
|
||||
## Enums
|
||||
|
||||
### [IdToken](LogtoClientErrors.IdToken.md)
|
||||
|
||||
## Typealiases
|
||||
|
||||
### [AccessToken](../Typealiases/LogtoClientErrors.AccessToken.md)
|
||||
### [JwkSet](../Typealiases/LogtoClientErrors.JwkSet.md)
|
||||
### [OidcConfig](../Typealiases/LogtoClientErrors.OidcConfig.md)
|
||||
### [SignIn](../Typealiases/LogtoClientErrors.SignIn.md)
|
||||
### [SignOut](../Typealiases/LogtoClientErrors.SignOut.md)
|
||||
### [UserInfo](../Typealiases/LogtoClientErrors.UserInfo.md)
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"position": 3
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"position": 4
|
||||
}
|
35
packages/docs/docs/sdk/Swift/LogtoClient/README.md
Normal file
35
packages/docs/docs/sdk/Swift/LogtoClient/README.md
Normal file
|
@ -0,0 +1,35 @@
|
|||
# LogtoClient Module
|
||||
|
||||
## Classes
|
||||
|
||||
- [LogtoClient](Classes/LogtoClient.md)
|
||||
|
||||
## Structs
|
||||
|
||||
- [AccessToken](Structs/AccessToken.md)
|
||||
- [LogtoClient.NotificationObject](Structs/LogtoClient.NotificationObject.md)
|
||||
- [LogtoConfig](Structs/LogtoConfig.md)
|
||||
- [LogtoError](Structs/LogtoError.md)
|
||||
## Enums
|
||||
|
||||
- [LogtoClientErrorTypes](Enums/LogtoClientErrorTypes.md)
|
||||
- [LogtoClientErrorTypes.AccessToken](Enums/LogtoClientErrorTypes.AccessToken.md)
|
||||
- [LogtoClientErrorTypes.JwkSet](Enums/LogtoClientErrorTypes.JwkSet.md)
|
||||
- [LogtoClientErrorTypes.OidcConfig](Enums/LogtoClientErrorTypes.OidcConfig.md)
|
||||
- [LogtoClientErrorTypes.SignIn](Enums/LogtoClientErrorTypes.SignIn.md)
|
||||
- [LogtoClientErrorTypes.SignOut](Enums/LogtoClientErrorTypes.SignOut.md)
|
||||
- [LogtoClientErrorTypes.UserInfo](Enums/LogtoClientErrorTypes.UserInfo.md)
|
||||
- [LogtoClientErrors](Enums/LogtoClientErrors.md)
|
||||
- [LogtoClientErrors.IdToken](Enums/LogtoClientErrors.IdToken.md)
|
||||
|
||||
## Typealiases
|
||||
|
||||
- [LogtoClientErrors.AccessToken](Typealiases/LogtoClientErrors.AccessToken.md)
|
||||
- [LogtoClientErrors.JwkSet](Typealiases/LogtoClientErrors.JwkSet.md)
|
||||
- [LogtoClientErrors.OidcConfig](Typealiases/LogtoClientErrors.OidcConfig.md)
|
||||
- [LogtoClientErrors.SignIn](Typealiases/LogtoClientErrors.SignIn.md)
|
||||
- [LogtoClientErrors.SignOut](Typealiases/LogtoClientErrors.SignOut.md)
|
||||
- [LogtoClientErrors.UserInfo](Typealiases/LogtoClientErrors.UserInfo.md)
|
||||
- [UnifiedViewController](Typealiases/UnifiedViewController.md)
|
||||
|
||||
This file was originally generated by [SourceDocs](https://github.com/eneko/SourceDocs)
|
|
@ -0,0 +1,26 @@
|
|||
**STRUCT**
|
||||
|
||||
# `AccessToken`
|
||||
|
||||
```swift
|
||||
public struct AccessToken: Codable
|
||||
```
|
||||
|
||||
## Properties
|
||||
### `token`
|
||||
|
||||
```swift
|
||||
public let token: String
|
||||
```
|
||||
|
||||
### `scope`
|
||||
|
||||
```swift
|
||||
public let scope: String
|
||||
```
|
||||
|
||||
### `expiresAt`
|
||||
|
||||
```swift
|
||||
public let expiresAt: TimeInterval
|
||||
```
|
|
@ -0,0 +1,20 @@
|
|||
**STRUCT**
|
||||
|
||||
# `LogtoClient.NotificationObject`
|
||||
|
||||
```swift
|
||||
public struct NotificationObject
|
||||
```
|
||||
|
||||
## Properties
|
||||
### `clientId`
|
||||
|
||||
```swift
|
||||
public let clientId: String?
|
||||
```
|
||||
|
||||
### `url`
|
||||
|
||||
```swift
|
||||
public let url: URL
|
||||
```
|
|
@ -0,0 +1,51 @@
|
|||
**STRUCT**
|
||||
|
||||
# `LogtoConfig`
|
||||
|
||||
```swift
|
||||
public struct LogtoConfig
|
||||
```
|
||||
|
||||
## Properties
|
||||
### `endpoint`
|
||||
|
||||
```swift
|
||||
public let endpoint: URL
|
||||
```
|
||||
|
||||
### `clientId`
|
||||
|
||||
```swift
|
||||
public let clientId: String
|
||||
```
|
||||
|
||||
### `resources`
|
||||
|
||||
```swift
|
||||
public let resources: [String]
|
||||
```
|
||||
|
||||
### `usingPersistStorage`
|
||||
|
||||
```swift
|
||||
public let usingPersistStorage: Bool
|
||||
```
|
||||
|
||||
### `scopes`
|
||||
|
||||
```swift
|
||||
public var scopes: [String]
|
||||
```
|
||||
|
||||
## Methods
|
||||
### `init(endpoint:clientId:scopes:resources:usingPersistStorage:)`
|
||||
|
||||
```swift
|
||||
public init(
|
||||
endpoint: String,
|
||||
clientId: String,
|
||||
scopes: [String] = [],
|
||||
resources: [String] = [],
|
||||
usingPersistStorage: Bool = true
|
||||
) throws
|
||||
```
|
|
@ -0,0 +1,20 @@
|
|||
**STRUCT**
|
||||
|
||||
# `LogtoError`
|
||||
|
||||
```swift
|
||||
public struct LogtoError<T>: LocalizedError
|
||||
```
|
||||
|
||||
## Properties
|
||||
### `type`
|
||||
|
||||
```swift
|
||||
public let type: T
|
||||
```
|
||||
|
||||
### `innerError`
|
||||
|
||||
```swift
|
||||
public let innerError: Error?
|
||||
```
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"position": 2
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
**TYPEALIAS**
|
||||
|
||||
# `LogtoClientErrors.AccessToken`
|
||||
|
||||
```swift
|
||||
public typealias AccessToken = LogtoError<LogtoClientErrorTypes.AccessToken>
|
||||
```
|
|
@ -0,0 +1,7 @@
|
|||
**TYPEALIAS**
|
||||
|
||||
# `LogtoClientErrors.JwkSet`
|
||||
|
||||
```swift
|
||||
public typealias JwkSet = LogtoError<LogtoClientErrorTypes.JwkSet>
|
||||
```
|
|
@ -0,0 +1,7 @@
|
|||
**TYPEALIAS**
|
||||
|
||||
# `LogtoClientErrors.OidcConfig`
|
||||
|
||||
```swift
|
||||
public typealias OidcConfig = LogtoError<LogtoClientErrorTypes.OidcConfig>
|
||||
```
|
|
@ -0,0 +1,7 @@
|
|||
**TYPEALIAS**
|
||||
|
||||
# `LogtoClientErrors.SignIn`
|
||||
|
||||
```swift
|
||||
public typealias SignIn = LogtoError<LogtoClientErrorTypes.SignIn>
|
||||
```
|
|
@ -0,0 +1,7 @@
|
|||
**TYPEALIAS**
|
||||
|
||||
# `LogtoClientErrors.SignOut`
|
||||
|
||||
```swift
|
||||
public typealias SignOut = LogtoError<LogtoClientErrorTypes.SignOut>
|
||||
```
|
|
@ -0,0 +1,7 @@
|
|||
**TYPEALIAS**
|
||||
|
||||
# `LogtoClientErrors.UserInfo`
|
||||
|
||||
```swift
|
||||
public typealias UserInfo = LogtoError<LogtoClientErrorTypes.UserInfo>
|
||||
```
|
|
@ -0,0 +1,7 @@
|
|||
**TYPEALIAS**
|
||||
|
||||
# `UnifiedViewController`
|
||||
|
||||
```swift
|
||||
public typealias UnifiedViewController = NSViewController | UIViewController
|
||||
```
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"position": 5
|
||||
}
|
|
@ -1 +1 @@
|
|||
# Swift SDK Reference
|
||||
# @logto-io/swift
|
||||
|
|
Loading…
Add table
Reference in a new issue