File tree 1 file changed +17
-1
lines changed
packages/providers/src/lib/push/apns
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ export class APNSPushProvider extends BaseProvider implements IPushProvider {
35
35
this . config = config ;
36
36
this . provider = new apn . Provider ( {
37
37
token : {
38
- key : config . key ,
38
+ key : this . validateAndFormatKey ( config . key ) ,
39
39
keyId : config . keyId ,
40
40
teamId : config . teamId ,
41
41
} ,
@@ -73,4 +73,20 @@ export class APNSPushProvider extends BaseProvider implements IPushProvider {
73
73
date : new Date ( ) . toISOString ( ) ,
74
74
} ;
75
75
}
76
+
77
+ private validateAndFormatKey ( key : string ) : string {
78
+ // Check if key is already properly formatted
79
+ const properFormat = / ^ - - - - - B E G I N P R I V A T E K E Y - - - - - \n [ A - Z a - z 0 - 9 + / = \n ] + \n - - - - - E N D P R I V A T E K E Y - - - - - $ / ;
80
+
81
+ if ( properFormat . test ( key ) ) {
82
+ return key ; // Key is already in correct format
83
+ }
84
+
85
+ // If not properly formatted, clean and format the key
86
+ const cleanKey = key . replace ( / - - - - - B E G I N P R I V A T E K E Y - - - - - | - - - - - E N D P R I V A T E K E Y - - - - - | [ \s \n \r ] / g, '' ) ;
87
+
88
+ const formattedKey = cleanKey . match ( / .{ 1 , 64 } / g) ?. join ( '\n' ) || '' ;
89
+
90
+ return `-----BEGIN PRIVATE KEY-----\n${ formattedKey } \n-----END PRIVATE KEY-----` ;
91
+ }
76
92
}
You can’t perform that action at this time.
0 commit comments