Ship Firebase Distant Notification with http v1 API from Swift, iOS utilizing AppAuth – Stack Overflow

Ship Firebase Distant Notification with http v1 API from Swift, iOS utilizing AppAuth – Stack Overflow


I’m making an attempt to obtain an entry token utilizing AppAuth for swift. The code i used will return an error:

Initiating authorization request with scope:
https://www.googleapis.com/auth/firebase.messaging Authorization
error: Der Vorgang konnte nicht abgeschlossen werden.
(org.openid.appauth.general-Fehler -3.)

The client_id, client_secret and redirect_uri are from google cloud console (OAuth 2.0-Shopper-IDs -> Internet shopper (auto created by Google Service)).

See this Screenshot: google cloud console

Edit:
When sending the request in my App, an alert opens after which instantly closes once more, asking me if i wish to grant permission for google.com to log in.

Possibly this Error Message is said to it:

“2024-10-30 18:23:57.498706+0100 Scholar App[97110:15504024] [Warning]
Making an attempt to load the view of a view controller whereas it’s
deallocating just isn’t allowed and will end in undefined habits
()”

   import UIKit
import FirebaseDatabase
import FirebaseAuth
import AppAuth
import AppAuthCore


class RemoteNotificationSender: UIViewController {
    func sendPushNotification(to topicPath: String, title: String, physique: String) {
        
        // property of the containing class
        var authState: OIDAuthState?
        var access_token = ""
        
        let ref = Database.database().reference()
        
        let urlString = "https://fcm.googleapis.com/v1/initiatives/fau-students/messages:ship"
        let url = NSURL(string: urlString)!
            
          
            
            let paramString: [String : Any] = ["message" : ["topic": "weather",
                                           "notification" : [
                                            "title" : title,
                                                             "body" : body
                                           ],
                                           "knowledge" : ["user" : "test_id"]
        ]
                                               ]
            
          

               let MESSAGING_SCOPE =
                 "https://www.googleapis.com/auth/firebase.messaging";
               let scopes = [MESSAGING_SCOPE];
        
       

            
        let authorizationEndpoint = URL(string: "https://accounts.google.com/o/oauth2/v2/auth")!
        let tokenEndpoint = URL(string: "https://www.googleapis.com/oauth2/v4/token")!
        let configuration = OIDServiceConfiguration(authorizationEndpoint: authorizationEndpoint,
                                                    tokenEndpoint: tokenEndpoint)

           
            
            
            
            // carry out the auth request...
            // builds authentication request
        
            let request_ = OIDAuthorizationRequest(configuration: configuration,
                                                   clientId: "",
                                                   clientSecret: "",
                                                   scopes: scopes,
                                                   redirectURL: URL(string: "")!,
                                                   responseType: OIDResponseTypeCode,
                                                   additionalParameters: nil)
            
            // performs authentication request
            print("Initiating authorization request with scope: (request_.scope ?? "nil")")
            
            let appDelegate = UIApplication.shared.delegate as! AppDelegate
            
            appDelegate.currentAuthorizationFlow =
            OIDAuthState.authState(byPresenting: request_ , presenting: self) { authState, error in
                if let authState = authState {
                    //self.setAuthState(authState)
                    
                    print("Acquired authorization tokens. Entry token: " +
                          "(authState.lastTokenResponse?.accessToken ?? "nil")")
                    access_token = authState.lastTokenResponse?.accessToken ?? "nil"
                } else {
                    print("Authorization error: (error?.localizedDescription ?? "Unknown error")")
                    //self.setAuthState(nil)
                }
            }
        
        
        let request = NSMutableURLRequest(url: url as URL)
        request.httpMethod = "POST"
        request.httpBody = strive? JSONSerialization.knowledge(withJSONObject:paramString, choices: [.prettyPrinted])
        request.setValue("utility/json", forHTTPHeaderField: "Content material-Kind")
        request.setValue("Bearer " + access_token, forHTTPHeaderField: "Authorization")
        let job =  URLSession.shared.dataTask(with: request as URLRequest)  { (knowledge, response, error) in
            do {
                if let jsonData = knowledge {
                    if let jsonDataDict  = strive JSONSerialization.jsonObject(with: jsonData, choices: JSONSerialization.ReadingOptions.allowFragments) as? [String: AnyObject] {
                        NSLog("FCM: Acquired knowledge:n(jsonDataDict))")
                    }
                }
            } catch let err as NSError {
                print(err.debugDescription)
            }
        }
        job.resume()
        
        
        
        //})
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *