### Install iOS CocoaPods Dependencies Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md After linking the library, this command navigates into the `ios` directory of your project and runs `pod install`. This step is essential for installing all CocoaPods dependencies required by `react-native-oauth` on iOS. ```bash (cd ios && pod install) ``` -------------------------------- ### Contributing to the Project Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Provides shell commands for cloning the repository, navigating into it, and installing dependencies to set up the project for development and contribution. ```shell git clone https://github.com/fullstackreact/react-native-oauth.git cd react-native-oauth npm install ``` -------------------------------- ### Install react-native-oauth via npm Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This command installs the `react-native-oauth` library into your React Native project using npm. The `--save` flag ensures it's added to your project's `package.json` dependencies. ```bash npm install --save react-native-oauth ``` -------------------------------- ### Automatically Link react-native-oauth using react-native link Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This `react-native` CLI command leverages `rnpm` to automatically link the `react-native-oauth` library to your React Native application. This automates much of the native module setup for both iOS and Android. ```bash react-native link react-native-oauth ``` -------------------------------- ### Configure OAuth Providers with react-native-oauth Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This JavaScript example shows how to configure multiple OAuth providers like Twitter and Facebook using the `manager.configure()` method. It accepts a configuration object containing consumer keys and secrets obtained from each provider's development dashboard. ```javascript const config = { twitter: { consumer_key: 'SOME_CONSUMER_KEY', consumer_secret: 'SOME_CONSUMER_SECRET' }, facebook: { client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET' } } // Create the manager const manager = new OAuthManager('firestackexample') // configure the manager manager.configure(config); ``` -------------------------------- ### Perform Basic OAuth Authorization using Manager in JavaScript Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This example shows how to use the `manager.authorize()` method to authenticate against a specified provider, such as 'twitter'. The method returns a Promise that resolves with a response object containing authentication keys upon successful completion, or rejects on error. ```javascript manager.authorize('twitter') .then(resp => console.log(resp)) .catch(err => console.log(err)); ``` -------------------------------- ### OAuthManager Class and Configuration API Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md API documentation for the `OAuthManager` class, including its constructor for initialization and the `configure` method for setting up multiple OAuth providers with their respective credentials. ```APIDOC OAuthManager: __init__(appName: string) appName: string - The name of the application. This must match the URL route created in your iOS app for callback keys. configure(config: object): Promise config: object - An object where keys are provider names (e.g., 'twitter', 'facebook') and values are objects containing provider-specific credentials. Example Structure: { "twitter": { "consumer_key": "string", "consumer_secret": "string" }, "facebook": { "client_id": "string", "client_secret": "string" } } Returns: Promise - A promise that resolves upon successful configuration. ``` -------------------------------- ### OAuthManager.addProvider() API Reference Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md API documentation for the `addProvider()` method, allowing the registration of custom OAuth providers with their specific configuration details. ```APIDOC OAuthManager.addProvider(providerConfig: object) providerConfig: An object where keys are provider names and values are provider details. name_of_provider: object - Configuration for a specific provider. auth_version: string - OAuth version (e.g., '2.0'). authorize_url: string - URL for the authorization endpoint. access_token_url: string - URL for the access token endpoint. callback_url: string | Function - The callback URL, can be a string or a function that returns a string (e.g., ({app_name}) => `${app_name}://oauth`). ``` -------------------------------- ### Initialize OAuthManager in iOS AppDelegate Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This Objective-C code snippet demonstrates how to initialize the `OAuthManager` within the `application:didFinishLaunchingWithOptions:` method in `ios/AppDelegate.m`. This ensures the OAuth handler is set up when the application launches. ```objectivec - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSURL *jsCodeLocation; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:"index.ios" fallbackResource:nil]; // other existing setup here // ADD THIS LINE SOMEWHERE IN THIS FUNCTION [OAuthManager setupOAuthHandler:application]; // ... [self.window makeKeyAndVisible]; return YES; } ``` -------------------------------- ### Make Request with Headers and Query Parameters Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Demonstrates how to pass additional options like custom headers and query parameters to `OAuthManager.makeRequest()` for more complex API interactions. ```javascript manager .makeRequest('facebook', '/me', { headers: { 'Content-Type': 'application/java' }, params: { email: 'me+rocks@ari.io' } }) .then(resp => { console.log('Data ->', resp.data); }); ``` -------------------------------- ### Configure Android build.gradle for Jitpack Repository Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This Gradle configuration adds the `jitpack.io` Maven repository to the `allprojects` section of the `android/build.gradle` file. This is essential for resolving dependencies required by `react-native-oauth`. ```gradle maven { url "https://jitpack.io" } ``` ```gradle // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { // ... } allprojects { repositories { mavenLocal() jcenter() maven { url "https://jitpack.io" } // <~ ADD THIS LINE maven { url "$rootDir/../node_modules/react-native/android" } } } ``` -------------------------------- ### Initialize OAuthManager in JavaScript Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This JavaScript snippet demonstrates how to create a new instance of `OAuthManager`. The constructor requires the application's name, which must match the URL scheme configured in the iOS app for callback keys. ```javascript const manager = new OAuthManager('firestackexample') ``` -------------------------------- ### Initialize OAuth Manager and Authorize Provider in JavaScript Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This JavaScript snippet demonstrates how to initialize the `OAuthManager` with specific OAuth 1.0/2.0 provider configurations (e.g., Twitter, Google) including consumer keys and callback URLs. It then shows how to authorize a user with a chosen provider (Google) using defined scopes, handling both successful responses and potential errors via promises. ```javascript import OAuthManager from 'react-native-oauth'; const manager = new OAuthManager('firestackexample') manager.configure({ twitter: { consumer_key: 'SOME_CONSUMER_KEY', consumer_secret: 'SOME_CONSUMER_SECRET' }, google: { callback_url: `io.fullstack.FirestackExample:/oauth2redirect`, client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_SECRET' } }); // ... manager.authorize('google', {scopes: 'profile email'}) .then(resp => console.log('Your users ID')) .catch(err => console.log('There was an error')); ``` -------------------------------- ### OAuthManager.makeRequest() API Reference Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Detailed API documentation for the `makeRequest()` method, used to send authenticated requests to OAuth providers. It supports full URLs or paths and optional request configurations. ```APIDOC OAuthManager.makeRequest(provider: string, url: string, options?: object) provider: The name of the OAuth provider (e.g., 'twitter', 'google', 'facebook'). url: The full URL or relative path to the API endpoint. options: Optional configuration object for the request. params: object - Query parameters to be sent with the request. method: string - HTTP method for the request (get, post, put, delete, head, options, trace). Returns: Promise - A promise that resolves with the API response data. ``` -------------------------------- ### Configure iOS AppDelegate for OAuth URL Handling Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This Objective-C snippet adds a callback method to `ios/AppDelegate.m` to handle incoming URLs from OAuth providers. It delegates the URL processing to the `OAuthManager` helper method. ```objectivec // Add the import at the top: #import "OAuthManager.h" // ... @implementation AppDelegate // ... - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [OAuthManager handleOpenUrl:application openURL:url sourceApplication:sourceApplication annotation:annotation]; } ``` -------------------------------- ### Convert XML Data to NSDictionary using XMLReader Source: https://github.com/fullstackreact/react-native-oauth/blob/master/ios/OAuthManager/XMLReader/README.md Demonstrates the basic usage of the XMLReader library to parse XML data into an NSDictionary. It shows how to pass NSData, specify parsing options like XMLReaderOptionsProcessNamespaces, and handle potential errors. ```Objective-C NSData *data = ...; // some data that can be received from remote service NSError *error = nil; NSDictionary *dict = [XMLReader dictionaryForXMLData:data options:XMLReaderOptionsProcessNamespaces error:&error]; ``` -------------------------------- ### Configure iOS Header Search Paths for OAuthManager Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This configuration snippet provides the necessary paths to add to your iOS project's `HEADER SEARCH PATHS` in Xcode. These paths are crucial for correctly linking the `react-native-oauth` library and the `RCTLinkingManager` from React Native core, enabling proper compilation and functionality. ```xcode-config $(SRCROOT)/../node_modules/react-native-oauth/ios/OAuthManager $(SRCROOT)/../node_modules/react-native/Libraries/LinkingIOS ``` -------------------------------- ### Configure Slack OAuth Credentials in JavaScript Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This snippet illustrates how to integrate the `client_id` and `client_secret` for Slack into your JavaScript configuration. These credentials, along with correctly configured redirect URLs, are necessary for enabling Slack authentication within your application. ```javascript const config = { slack: { client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET' } } ``` -------------------------------- ### Configure Google OAuth Provider for React Native (iOS) Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Instructions for configuring Google OAuth authentication for iOS in `react-native-oauth`. Requires creating a Google application, enabling the `Identity Toolkit API`, creating an iOS API credential, noting the `client_id` and `iOS URL scheme`, and adding the URL scheme to the Xcode Info panel. ```javascript const config = { google: { callback_url: `[IOS SCHEME]:/google`, client_id: 'YOUR_CLIENT_ID' } } ``` -------------------------------- ### Configure Github OAuth Credentials in JavaScript Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This snippet demonstrates how to add the `client_id` and `client_secret` obtained from the Github developer applications page into your JavaScript configuration object. These credentials are essential for authenticating with Github for both iOS and Android platforms. ```javascript const config = { github: { client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET' } } ``` -------------------------------- ### Make Request to Facebook API with Path Only Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Illustrates using `OAuthManager.makeRequest()` with a relative path (`/me`) for the Facebook API, demonstrating flexibility in URL specification. ```javascript manager .makeRequest('facebook', '/me') .then(resp => { console.log('Data ->', resp.data); }); ``` -------------------------------- ### Add a Custom OAuth Provider Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Illustrates how to extend `OAuthManager` by adding a new custom OAuth provider using `addProvider()`, specifying its authorization and token URLs, and callback URL. ```javascript manager.addProvider({ 'name_of_provider': { auth_version: '2.0', authorize_url: 'https://provider.dev/oauth', access_token_url: 'https://provider.dev/oauth/token', callback_url: ({app_name}) => `${app_name}://oauth`, } }); ``` -------------------------------- ### Configure Twitter OAuth Provider for React Native Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Instructions for configuring Twitter OAuth authentication in `react-native-oauth`. Requires registering a Twitter application, obtaining consumer key and secret, setting a callback URL, and ensuring the Xcode URL scheme matches the app name. ```javascript const config = { twitter: { consumer_key: 'SOME_CONSUMER_KEY', consumer_secret: 'SOME_CONSUMER_SECRET' } } ``` -------------------------------- ### Configure Facebook OAuth Provider for React Native Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Instructions for configuring Facebook OAuth authentication in `react-native-oauth`. Requires creating a Facebook app, noting the app ID and client secret, setting the bundle ID (e.g., `fb{YOUR_APP_ID}`), and for Android, setting the redirect URL to `http://localhost/facebook`. Also, ensure the Facebook redirect URL scheme is the first in the Xcode list. ```javascript const config = { facebook: { client_id: 'YOUR_APP_ID', client_secret: 'YOUR_APP_SECRET' } } ``` -------------------------------- ### Make Request to Google+ API for Authenticated User Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Shows how to use `OAuthManager.makeRequest()` to retrieve information about the authenticated user ('me') from the Google+ API using a full URL. ```javascript const googleUrl = 'https://www.googleapis.com/plus/v1/people/me'; manager .makeRequest('google', googleUrl) .then(resp => { console.log('Data -> ', resp.data); }); ``` -------------------------------- ### Make Request to Twitter API Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Demonstrates how to use `OAuthManager.makeRequest()` to fetch a user's timeline from Twitter's API after authorization. It uses the full URL. ```javascript const userTimelineUrl = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; manager .makeRequest('twitter', userTimelineUrl) .then(resp => { console.log('Data ->', resp.data); }); ``` -------------------------------- ### Perform OAuth Authorization with Custom Scopes in JavaScript Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This snippet demonstrates how to pass an optional second argument to `manager.authorize()` to request specific permissions (scopes) from the OAuth provider, such as 'email' and 'profile' for Google. Scopes should be provided as a comma-separated string. ```javascript manager.authorize('google', {scopes: 'email,profile'}) .then(resp => console.log(resp)) .catch(err => console.log(err)); ``` -------------------------------- ### Retrieve List of Authorized Accounts Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Shows how to use `OAuthManager.savedAccounts()` to query and retrieve a list of all accounts that have been previously authorized and stored by the OAuthManager. ```javascript manager.savedAccounts() .then(resp => { console.log('account list: ', resp.accounts); }); ``` -------------------------------- ### API Response Structure for OAuth Authorization Method Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md This defines the expected structure of the response object returned by the `manager.authorize()` method. It includes the authentication status, a boolean indicating authorization, the user's UUID, and credential details such as access and refresh tokens. ```APIDOC { status: "ok", response: { authorized: true, (boolean) uuid: "UUID", (user UUID) credentials: { access_token: "access token", refresh_token: "refresh token", type: 1 } } } ``` -------------------------------- ### OAuthManager.savedAccounts() API Reference Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md API documentation for the `savedAccounts()` method, which retrieves a list of all accounts currently authorized and stored by the OAuthManager. ```APIDOC OAuthManager.savedAccounts() Returns: Promise<{accounts: Array}> - A promise that resolves with an object containing a list of authorized accounts. ``` -------------------------------- ### Safely Handle Single-Item XML Lists as NSArray Source: https://github.com/fullstackreact/react-native-oauth/blob/master/ios/OAuthManager/XMLReader/README.md Provides a workaround for the XMLReader's behavior where a list with a single item might be returned as an NSDictionary instead of an NSArray. This snippet demonstrates how to check the object's class and convert it to an NSArray if necessary, ensuring safe iteration. ```Objective-C NSData *data = ...; NSError *error = nil; NSDictionary *dict = [XMLReader dictionaryForXMLData:data error:&error]; NSArray *list = [dict objectForKey:@"list"]; if (![list isKindOfClass:[NSArray class]]) { // if 'list' isn't an array, we create a new array containing our object list = [NSArray arrayWithObject:list]; } // we can loop through items safely now for (NSDictionary *item in list) { // ... } ``` -------------------------------- ### OAuthManager.deauthorize() API Reference Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md API documentation for the `deauthorize()` method, used to revoke authorization for a specific provider and remove its credentials. ```APIDOC OAuthManager.deauthorize(provider: string) provider: The name of the provider to deauthorize. ``` -------------------------------- ### Deauthorize a Specific Provider Source: https://github.com/fullstackreact/react-native-oauth/blob/master/README.md Explains how to use `OAuthManager.deauthorize()` to remove a specific provider's credentials from the user's stored authorizations. ```javascript manager.deauthorize('twitter'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.