Skip to main content

Swift API Manager -Alamofire-Refresh Token-With TestCases

  import Foundation import KeychainAccess enum APIError : Error { case accessTokenExpired case networkError // Add more error cases as needed } class APIManager { private let keychain = Keychain (service: "com.example.app.refreshToken" ) private let refreshTokenKey = "refreshToken" private var accessToken: String ? func callAPI < T : Codable >( urlString : String , method : String , parameters : [ String : Any ] ? , completion : @escaping ( Result < T , APIError >) -> Void ) { guard let url = URL (string: urlString) else { completion(.failure(.networkError)) return } var request = URLRequest (url: url) request.httpMethod = method // Add access token to the request headers if available if let token = accessToken { request.setValue( "Bearer \(token) " , forHTTPHeaderField: "Aut...

Integrating Google reCAPTCHA Enterprise in iOS apps Swift and Google Cloud

Google ReCaptcha =>> Integrating Google reCAPTCHA Enterprise in iOS apps Swift

If are you implement reCAPTCHA Enterprise,  then you contact Contact our sales team for reCAPTCHA Enterprise iOS SDK is accessible after a security review. Then Create a reCAPTCHA Key for the iOS app platform.

Step by Step

  1.  Choose the best method for setting up reCAPTCHA Enterprise in your environment and complete the setup.
  2. iOS SDK is accessible after a security review. Contact our sales team to onboard your site to this feature.
  3.  Create a reCAPTCHA Key for the iOS app platform.

Then Depending on your integration method, ask your sales representative to grant you access to one of the following: reCAPTCHA Enterprise CocoaPods repository, the Swift Package Manager repository, or the iOS SDK download .

Integrating reCAPTCHA Enterprise Two Way:- 

  1. Direct download => Download the SDK binary from the iOS SDK download page. - https://cloud.google.com/recaptcha-enterprise/docs/download-ios-sdk
  2. Download the SDK using CocoaPods

  •   Generate a git cookie.
  •   Create a Podfile and add the following lines to your Podfile:

     source "https://cpdc-eap.googlesource.com/RecaptchaEnterprise.git"

     source "https://github.com/CocoaPods/Specs.git"

     pod "RecaptchaEnterprise", "17.0.0"

  •   Install the required dependencies by running pod update.

After Install CocoaPods - Configuring the app

 1. To ensure that -ObjC is listed on your linker flags, navigate to Target > Build Settings > All > Linking and verify that Other Linker Flags shows -ObjC.

 2. Objective-C bridging header File Add, Import

    #import <recaptcha/recaptcha.h>


Implement with in ViewController

let recaptchaClient = RecaptchaClient(siteKey: "reCAPTCHA_KEY_iOS")


Call to the execute() method to return a reCAPTCHA token

    func enterpriseReCaptcha(){

        recaptchaClient.execute(RecaptchaAction(action: .login)) { token, error in

            if let recaptchaToken = token {

                print(recaptchaToken.recaptchaToken)

            }

            if let error = error {

                print(error)

            }

        }

    }

Reference ==> https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps#direct-download

Comments