import * as applicationModule from "application" ; import * as utils from "utils/utils" ; import { AuthHelperOffice365 } from "./auth-helper-office365" ; import { AuthHelperFacebook } from "./auth-helper-facebook" ; import { AuthHelperGoogle } from "./auth-helper-google" ; import { AuthHelperUaa } from "./auth-helper-uaa" ; import { AuthHelperLinkedIn } from "./auth-helper-linkedin" ; import { AuthHelperSalesforce } from "./auth-helper-salesforce" ; import { AuthHelperCustom } from "./auth-helper-custom" ; import * as TnsOAuth from "./tns-oauth-interfaces" ; export var instance = null ; export function initOffice365 ( options ) { console . error ( "This plugin is deprecated, Please use the new nativescript-oauth2 plugin" ) ; return new Promise ( function ( resolve , reject ) { try { if ( instance !== null ) { reject ( "You already ran init" ) ; return ; } instance = new AuthHelperOffice365 ( options . clientId , options . scope ) ; resolve ( instance ) ; } catch ( ex ) { console . log ( "Error in AuthHelperOffice365.init: " + ex ) ; reject ( ex ) ; } } ) ; } export function initFacebook ( options ) { console . error ( "This plugin is deprecated, Please use the new nativescript-oauth2 plugin" ) ; return new Promise ( function ( resolve , reject ) { try { if ( instance !== null ) { reject ( "You already ran init" ) ; return ; } instance = new AuthHelperFacebook ( options . clientId , options . clientSecret , options . scope ) ; resolve ( instance ) ; } catch ( ex ) { console . log ( "Error in AuthHelperFacebook.init: " + ex ) ; reject ( ex ) ; } } ) ; } export function initGoogle ( options ) { console . error ( "This plugin is deprecated, Please use the new nativescript-oauth2 plugin" ) ; return new Promise ( function ( resolve , reject ) { try { if ( instance !== null ) { reject ( "You already ran init" ) ; return ; } instance = new AuthHelperGoogle ( options . clientId , options . scope ) ; resolve ( instance ) ; } catch ( ex ) { console . log ( "Error in AuthHelperGoogle.init: " + ex ) ; reject ( ex ) ; } } ) ; } export function initUaa ( options ) { console . error ( "This plugin is deprecated, Please use the new nativescript-oauth2 plugin" ) ; return new Promise ( function ( resolve , reject ) { try { if ( instance !== null ) { reject ( "You already ran init" ) ; return ; } instance = new AuthHelperUaa ( options . authority , options . redirectUri , options . clientId , options . clientSecret , options . scope , options . cookieDomains , options . basicAuthHeader ) ; resolve ( instance ) ; } catch ( ex ) { console . log ( "Error in AuthHelperUaa.init: " + ex ) ; reject ( ex ) ; } } ) ; } export function initLinkedIn ( options ) { console . error ( "This plugin is deprecated, Please use the new nativescript-oauth2 plugin" ) ; return new Promise ( function ( resolve , reject ) { try { if ( instance !== null ) { reject ( "You already ran init" ) ; return ; } instance = new AuthHelperLinkedIn ( options . clientId , options . clientSecret , options . redirectUri , options . scope ) ; resolve ( instance ) ; } catch ( ex ) { console . log ( "Error in AuthHelperLinkedIn.init: " + ex ) ; reject ( ex ) ; } } ) ; } export function initSalesforce ( options ) { console . error ( "This plugin is deprecated, Please use the new nativescript-oauth2 plugin" ) ; return new Promise ( function ( resolve , reject ) { try { if ( instance !== null ) { reject ( "You already ran init" ) ; return ; } instance = new AuthHelperSalesforce ( options . authority , options . clientId , options . redirectUri , options . responseType , options . scope ) ; resolve ( instance ) ; } catch ( ex ) { console . log ( "Error in AuthHelperSalesforce.init: " + ex ) ; reject ( ex ) ; } } ) ; } export function initCustom ( options ) { console . error ( "This plugin is deprecated, Please use the new nativescript-oauth2 plugin" ) ; return new Promise ( function ( resolve , reject ) { try { if ( instance !== null ) { reject ( "You already ran init" ) ; return ; } instance = new AuthHelperCustom ( options . credentials , options . cookieDomains ) ; resolve ( instance ) ; } catch ( ex ) { console . log ( "Error in AuthHelperCustom.init: " + ex ) ; reject ( ex ) ; } } ) ; } export function accessToken ( ) { return instance . tokenResult . accessToken ; } export function login ( successPage ? ) { console . error ( "This plugin is deprecated, Please use the new nativescript-oauth2 plugin" ) ; return instance . login ( successPage ) ; } export function logout ( successPage ? ) { return instance . logout ( successPage ) ; } export function accessTokenExpired ( ) { return instance . accessTokenExpired ( ) ; } export function ensureValidToken ( ) { return new Promise ( ( resolve , reject ) => { if ( instance . accessTokenExpired ( ) ) { if ( instance . refreshTokenExpired ( ) ) { login ( ) . then ( ( response ) => { resolve ( response ) ; } ) . catch ( er => { reject ( er ) ; } ) ; } else { instance . refreshToken ( ) . then ( ( result ) => { resolve ( result ) ; } ) . catch ( er => { reject ( ErrorEvent ) ; } ) ; } } else { resolve ( accessToken ( ) ) ; } } ) ; }