Welcome to the documentation for OhMyAuth, a powerful authentication library for iOS and macOS developers. This comprehensive guide will help you integrate OhMyAuth into your projects and understand its features and capabilities.
Installation
To get started with OhMyAuth, you need to follow these simple steps:
- Ensure that you have the latest version of Xcode installed on your machine.
- Open your project in Xcode.
- Add OhMyAuth as a dependency to your project using one of the following methods:
- CocoaPods: Add the following line to your Podfile:
pod 'OhMyAuth'
. Then runpod install
to install the library. - Carthage: Add the following line to your Cartfile:
github "ohmyauth/ohmyauth"
. Then runcarthage update
to fetch and build the library. - Manual: Download the latest OhMyAuth framework from the official GitHub repository (link) and manually add it to your project.
- CocoaPods: Add the following line to your Podfile:
- Start integrating OhMyAuth into your app by following the usage instructions in the next sections.
Usage
Basic Authentication
OhMyAuth provides a straightforward way to authenticate users using basic authentication.
- Import the OhMyAuth framework into your class:
import OhMyAuth
. - Create an instance of the
Authenticator
class. - Set the
username
andpassword
properties of theAuthenticator
instance. - Call the
authenticate
method on theAuthenticator
instance. - Handle the authentication result using the provided closure.
OAuth2 Authentication
If you prefer using OAuth2 for authentication, OhMyAuth has you covered.
- Import the OhMyAuth framework into your class:
import OhMyAuth
. - Create an instance of the
OAuth2Authenticator
class. - Configure the required OAuth2 parameters such as
clientId
,clientSecret
, andredirectURI
. - Call the
authorize
method on theOAuth2Authenticator
instance. - Handle the authorization result using the provided closure.
Additional Features
Keychain Integration
OhMyAuth includes built-in keychain integration, allowing you to securely store user credentials and tokens.
- Create an instance of the
KeychainManager
class. - Use the provided methods to store and retrieve data securely in the keychain.
JWT Support
OhMyAuth supports JSON Web Tokens (JWT) for enhanced security and flexibility.
- Use the
JWTEncoder
andJWTDecoder
classes to generate and verify JWTs respectively. - Configure the required JWT parameters such as
algorithm
andsecret
. - Encode and sign data using the
encode
method. - Verify and decode JWTs using the
verify
method.
Conclusion
With OhMyAuth, you have a powerful and versatile authentication library at your disposal. It simplifies the authentication process and provides robust security features.
Refer to the detailed API documentation for more information about OhMyAuth’s classes, methods, and properties.