| 47 | |
| 48 | let provider; |
| 49 | export class AppCheck implements IAppCheck { |
| 50 | _native: FIRAppCheck; |
| 51 | _nativeApp; |
| 52 | _app: FirebaseApp; |
| 53 | constructor(app?: FirebaseApp) { |
| 54 | if (app?.native) { |
| 55 | this._native = FIRAppCheck.appCheckWithApp(app.native); |
| 56 | this._nativeApp = app.native; |
| 57 | } else { |
| 58 | if (defaultAppCheck) { |
| 59 | return defaultAppCheck; |
| 60 | } |
| 61 | defaultAppCheck = this; |
| 62 | this._native = FIRAppCheck.appCheck(); |
| 63 | this._nativeApp = FIRApp.defaultApp(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | static setProviderFactory() { |
| 68 | if (!provider) { |
| 69 | provider = FIRAppCheckDebugProviderFactory.alloc().init(); |
| 70 | } |
| 71 | FIRAppCheck.setAppCheckProviderFactory(provider); |
| 72 | } |
| 73 | |
| 74 | activate(isTokenAutoRefreshEnabled: boolean) { |
| 75 | this.native.isTokenAutoRefreshEnabled = isTokenAutoRefreshEnabled; |
| 76 | } |
| 77 | getToken(forceRefresh: boolean): Promise<AppCheckToken> { |
| 78 | return new Promise((resolve, reject) => { |
| 79 | this.native.tokenForcingRefreshCompletion(forceRefresh, (token, error) => { |
| 80 | if (error) { |
| 81 | const err = FirebaseError.fromNative(error); |
| 82 | reject(err); |
| 83 | } else { |
| 84 | resolve(AppCheckToken.fromNative(token)); |
| 85 | } |
| 86 | }); |
| 87 | }); |
| 88 | } |
| 89 | setTokenAutoRefreshEnabled(enabled: boolean) { |
| 90 | this.native.isTokenAutoRefreshEnabled = enabled; |
| 91 | } |
| 92 | get native() { |
| 93 | return this._native; |
| 94 | } |
| 95 | get ios() { |
| 96 | return this.native; |
| 97 | } |
| 98 | get app(): FirebaseApp { |
| 99 | if (!this._app) { |
| 100 | // @ts-ignore |
| 101 | this._app = FirebaseApp.fromNative(this._nativeApp); |
| 102 | } |
| 103 | return this._app; |
| 104 | } |
| 105 | } |
nothing calls this directly
no outgoing calls
no test coverage detected