Monday, July 22, 2024
HomeiOS Developmentswift - iOS DeviceCheck API name returning 400 on a regular basis

swift – iOS DeviceCheck API name returning 400 on a regular basis


I am getting 400 Lacking or badly formatted authorization token everytime I name the next API from my native Server ( I attempted calling this API from my app itself as nicely)

curl --location 'https://api.improvement.devicecheck.apple.com/v1/query_two_bits' 
--header 'Authorization: Bearer <<JWT-token>>' 
--header 'Content material-Sort: software/json' 
--data '{
    "device_token": Token_fetched_from_Device_Check,
    "transaction_id":"c6bdb659-0ee6-443d-88cb-a8f036dfc551", 
    "timestamp": 1721300244267
}'

"device_token" - I've generated from DeviceCheck framework

JWT-token - I generated utilizing key from .p8 file generated from Apple developer portal, keyId of the identical and the crew Id ( I've particular person account)

IMP Factors-

  1. I’ve created this .p8 file from apple developer account, and I did allow System examine choice whereas creating the important thing.
  2. I additionally tried calling this API after 7 hours ( and extra then that as nicely) of making key from the developer portal as I’ve learn someplace that the important thing will get activated after few hours.
  3. I perceive (once more learn someplace) that the token created by DeviceCheck framework has some expiration time so I attempted with freshly created token a number of occasions as nicely.

That is how I am producing token utilizing DeviceCheck –

if curDevice.isSupported{
     DCDevice.present.generateToken { (knowledge, error) in
           if let knowledge = knowledge {
           }
     }
 }

JWT token technology –

func createJWTToken(privateKey: String, keyID: String, teamID: String) -> String? {
        // Arrange the JWT header
        var jwtHeader = Header()
        jwtHeader.child = keyID
        
        // Arrange the JWT claims
        let jwtClaims = MyClaims(iss: teamID, iat: Date())
        
        // Create the JWT
        var jwt = JWT(header: jwtHeader, claims: jwtClaims)
        
        // Convert the personal key to Knowledge
        guard let privateKeyData = Knowledge(base64Encoded: privateKey) else {
            print("Invalid personal key")
            return nil
        }
        
        
        // Signal the JWT
        let jwtSigner = JWTSigner.es256(privateKey: privateKeyData)
        
        do {
            let signedJWT = strive jwt.signal(utilizing: jwtSigner)
            return signedJWT
        } catch {
            print("Did not signal JWT: (error)")
            return nil
        }
    }

However no luck, please counsel one thing. any kind of assist is way appreciated.

Thanks



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments