diff --git a/.npmignore b/.npmignore
index 3a58dd5..0f3d1ed 100755
--- a/.npmignore
+++ b/.npmignore
@@ -1,3 +1,12 @@
demo/
+node_modules/
+hooks/
*.png
-*.log
\ No newline at end of file
+*.log
+*.ts
+*.js.map
+tsconfig.json
+
+!index.d.ts
+!tns-oauth-interfaces.d.ts
+!*.js
diff --git a/auth-helper-facebook.ts b/auth-helper-facebook.ts
index 5a5ebca..0808d87 100644
--- a/auth-helper-facebook.ts
+++ b/auth-helper-facebook.ts
@@ -1,5 +1,8 @@
+///
+
import * as tnsOauth from './tns-oauth';
import { AuthHelper } from './auth-helper';
+import * as TnsOAuth from './tns-oauth-interfaces';
export class AuthHelperFacebook extends AuthHelper implements TnsOAuth.ITnsAuthHelper {
diff --git a/auth-helper-google.ts b/auth-helper-google.ts
index 8ae84cc..fa6caac 100644
--- a/auth-helper-google.ts
+++ b/auth-helper-google.ts
@@ -1,5 +1,8 @@
+///
+
import * as tnsOauth from './tns-oauth';
import { AuthHelper } from './auth-helper';
+import * as TnsOAuth from './tns-oauth-interfaces';
export class AuthHelperGoogle extends AuthHelper implements TnsOAuth.ITnsAuthHelper {
diff --git a/auth-helper-office365.ts b/auth-helper-office365.ts
index 9c88bee..f32f39b 100644
--- a/auth-helper-office365.ts
+++ b/auth-helper-office365.ts
@@ -1,5 +1,8 @@
+///
+
import * as tnsOauth from './tns-oauth';
import { AuthHelper } from './auth-helper';
+import * as TnsOAuth from './tns-oauth-interfaces';
export class AuthHelperOffice365 extends AuthHelper implements TnsOAuth.ITnsAuthHelper {
diff --git a/auth-helper.ts b/auth-helper.ts
index 53f45bb..ce79184 100644
--- a/auth-helper.ts
+++ b/auth-helper.ts
@@ -1,6 +1,7 @@
-///
+///
import * as tnsOauth from './tns-oauth';
+import * as TnsOAuth from './tns-oauth-interfaces';
export class AuthHelper {
public credentials: TnsOAuth.ITnsOAuthCredentials;
diff --git a/index.d.ts b/index.d.ts
index 375b025..9d9ede2 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,15 +1,14 @@
-///
-///
-declare module "nativescript-oauth" {
- export function initOffice365(options: TnsOAuth.ITnsOAuthOptionsOffice365): Promise;
- export function initFacebook(options: TnsOAuth.ITnsOAuthOptionsFacebook): Promise;
- export function initGoogle(options: TnsOAuth.ITnsOAuthOptionsGoogle): Promise;
+import * as TnsOAuth from './tns-oauth-interfaces';
+export * from './tns-oauth-interfaces';
- export function accessToken() : string;
- export function login(successPage?: string) : Promise;
- export function logout(successPage: string) : Promise;
- export function accessTokenExpired() : boolean;
- export function ensureValidToken() : Promise;
-}
+export declare var instance: TnsOAuth.ITnsAuthHelper;
+export declare function initOffice365(options: TnsOAuth.ITnsOAuthOptionsOffice365): Promise;
+export declare function initFacebook(options: TnsOAuth.ITnsOAuthOptionsFacebook): Promise;
+export declare function initGoogle(options: TnsOAuth.ITnsOAuthOptionsGoogle): Promise;
+export declare function accessToken(): string;
+export declare function login(successPage?: string): Promise;
+export declare function logout(successPage: string): Promise;
+export declare function accessTokenExpired(): boolean;
+export declare function ensureValidToken(): Promise;
diff --git a/index.ts b/index.ts
index 6696d44..919afec 100644
--- a/index.ts
+++ b/index.ts
@@ -1,8 +1,13 @@
+///
+
+
+
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 * as TnsOAuth from './tns-oauth-interfaces';
export var instance : TnsOAuth.ITnsAuthHelper = null;
diff --git a/package.json b/package.json
index ee77339..f87934f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "nativescript-oauth",
- "version": "0.9.1",
+ "version": "0.9.2",
"description": "OAuth 2 login for NativeScript.",
"main": "index.js",
"nativescript": {
@@ -20,6 +20,10 @@
"type": "git",
"url": "https://github.com/alexziskind1/nativescript-oauth.git"
},
+ "typescript": {
+ "definition": "index.d.ts"
+ },
+ "typings": "index",
"keywords": [
"NativeScript",
"JavaScript",
@@ -33,13 +37,13 @@
"author": {
"name": "Alexander Ziskind",
"email": "alex@nuvious.com",
- "url" : "http://www.nuvious.com/blog"
+ "url": "http://www.nuvious.com/blog"
},
"contributors": [
{
"name": "Kevin Primm",
"email": "kfprimm@gmail.com",
- "url" : "http://primm.me/"
+ "url": "https://github.com/kfprimm"
}
],
"bugs": {
@@ -52,12 +56,12 @@
"homepage": "https://github.com/alexziskind1/nativescript-oauth",
"readmeFilename": "README.md",
"dependencies": {
- "querystring": "^0.2.0",
- "url": "^0.11.0"
+ "url": "^0.11.0",
+ "querystring": "^0.2.0"
},
"devDependencies": {
- "typescript": "^1.8.10",
+ "nativescript-dev-typescript": "^0.3.0",
"tns-core-modules": "^2.1.0",
- "nativescript-dev-typescript": "^0.3.0"
+ "typescript": "^1.8.10"
}
}
diff --git a/references.d.ts b/references.d.ts
index 8f857a9..4eae0f9 100644
--- a/references.d.ts
+++ b/references.d.ts
@@ -1 +1,7 @@
-/// Needed for autocompletion and compilation.
+///
+///
+///
+///
+///
+///
+///
\ No newline at end of file
diff --git a/tns-oauth-interfaces.d.ts b/tns-oauth-interfaces.d.ts
index fce9344..1c910bf 100644
--- a/tns-oauth-interfaces.d.ts
+++ b/tns-oauth-interfaces.d.ts
@@ -1,45 +1,45 @@
-declare module TnsOAuth {
- interface ITnsAuthHelper {
- credentials: ITnsOAuthCredentials;
- tokenResult: ITnsOAuthTokenResult;
- login: (successPage?: string) => Promise;
- logout: (successPage: string) => Promise<{}>;
- refreshToken: () => Promise;
- accessTokenExpired: () => boolean;
- refreshTokenExpired: () => boolean;
- }
-
- interface ITnsOAuthCredentials {
- authority: string;
- tokenEndpointBase?: string;
- authorizeEndpoint: string;
- tokenEndpoint: string;
- clientId: string;
- clientSecret?: string;
- redirectUri: string;
- scope: string;
- }
-
- interface ITnsOAuthTokenResult {
- accessToken: string;
- refreshToken: string;
- accessTokenExpiration: Date;
- refreshTokenExpiration: Date;
- }
-
- interface ITnsOAuthOptions {
- clientId: string;
- scope: string[];
- }
-
- interface ITnsOAuthOptionsOffice365 extends ITnsOAuthOptions {
- }
-
- interface ITnsOAuthOptionsFacebook extends ITnsOAuthOptions {
- clientSecret: string;
- }
-
- interface ITnsOAuthOptionsGoogle extends ITnsOAuthOptions {
- }
+
+
+export interface ITnsAuthHelper {
+ credentials: ITnsOAuthCredentials;
+ tokenResult: ITnsOAuthTokenResult;
+ login: (successPage?: string) => Promise;
+ logout: (successPage: string) => Promise<{}>;
+ refreshToken: () => Promise;
+ accessTokenExpired: () => boolean;
+ refreshTokenExpired: () => boolean;
+}
+
+export interface ITnsOAuthCredentials {
+ authority: string;
+ tokenEndpointBase?: string;
+ authorizeEndpoint: string;
+ tokenEndpoint: string;
+ clientId: string;
+ clientSecret?: string;
+ redirectUri: string;
+ scope: string;
+}
+
+export interface ITnsOAuthTokenResult {
+ accessToken: string;
+ refreshToken: string;
+ accessTokenExpiration: Date;
+ refreshTokenExpiration: Date;
+}
+
+export interface ITnsOAuthOptions {
+ clientId: string;
+ scope: string[];
+}
+
+export interface ITnsOAuthOptionsOffice365 extends ITnsOAuthOptions {
+}
+
+export interface ITnsOAuthOptionsFacebook extends ITnsOAuthOptions {
+ clientSecret: string;
+}
+
+export interface ITnsOAuthOptionsGoogle extends ITnsOAuthOptions {
}
\ No newline at end of file
diff --git a/tns-oauth-page-provider.ts b/tns-oauth-page-provider.ts
index 7dfcaf7..63dd6ca 100644
--- a/tns-oauth-page-provider.ts
+++ b/tns-oauth-page-provider.ts
@@ -1,8 +1,10 @@
+///
+
import { Page } from 'ui/page';
import { GridLayout } from 'ui/layouts/grid-layout';
import { StackLayout } from 'ui/layouts/stack-layout';
import { WebView } from 'ui/web-view';
-import { TnsOAuthWebViewDelegateImpl } from './tns-oauth-webview';
+//import { TnsOAuthWebViewDelegateImpl } from './tns-oauth-webview';
import { TnsOAuthWebViewHelper } from './tns-oauth-webview-helper';
diff --git a/tns-oauth-token-cache.ts b/tns-oauth-token-cache.ts
index 62194ff..470f494 100644
--- a/tns-oauth-token-cache.ts
+++ b/tns-oauth-token-cache.ts
@@ -1,3 +1,7 @@
+///
+
+import * as TnsOAuth from './tns-oauth-interfaces';
+
import * as applicationSettingsModule from "application-settings";
const TNS_OAUTH_KEY = "TNS_OAUTH_KEY";
diff --git a/tns-oauth-webview-helper.android.ts b/tns-oauth-webview-helper.android.ts
index d54331e..6c529c7 100644
--- a/tns-oauth-webview-helper.android.ts
+++ b/tns-oauth-webview-helper.android.ts
@@ -1,3 +1,5 @@
+///
+
import { WebView } from 'ui/web-view';
import trace = require("trace");
diff --git a/tns-oauth-webview-helper.d.ts b/tns-oauth-webview-helper.d.ts
index ab21dcf..fd79ca5 100644
--- a/tns-oauth-webview-helper.d.ts
+++ b/tns-oauth-webview-helper.d.ts
@@ -1,3 +1,5 @@
+///
+
import { WebView } from 'ui/web-view';
export declare class TnsOAuthWebViewHelper {
diff --git a/tns-oauth-webview-helper.ios.ts b/tns-oauth-webview-helper.ios.ts
index 8c6b17d..efaf9ad 100644
--- a/tns-oauth-webview-helper.ios.ts
+++ b/tns-oauth-webview-helper.ios.ts
@@ -1,3 +1,5 @@
+///
+
import { WebView } from 'ui/web-view';
export class TnsOAuthWebViewHelper extends NSObject implements UIWebViewDelegate {
diff --git a/tns-oauth-webview.ts b/tns-oauth-webview.ts
index 6d7d228..c6d7da0 100644
--- a/tns-oauth-webview.ts
+++ b/tns-oauth-webview.ts
@@ -1,3 +1,5 @@
+///
+
import { WebView } from 'ui/web-view';
export class TnsOAuthWebViewDelegateImpl extends NSObject implements UIWebViewDelegate {
diff --git a/tns-oauth.ts b/tns-oauth.ts
index c71c90f..4073e86 100644
--- a/tns-oauth.ts
+++ b/tns-oauth.ts
@@ -1,3 +1,6 @@
+///
+
+
import * as querystring from 'querystring';
import * as URL from 'url';
import * as http from 'http';
@@ -7,6 +10,7 @@ import * as uuid from './tns-oauth-uuid';
import * as utils from './tns-oauth-utils';
import { TnsOAuthPageProvider } from './tns-oauth-page-provider';
import { TnsOAuthTokenCache } from './tns-oauth-token-cache';
+import * as TnsOAuthModule from './tns-oauth-interfaces';
export var ACCESS_TOKEN_CACHE_KEY = 'ACCESS_TOKEN_CACHE_KEY';
export var REFRESH_TOKEN_CACHE_KEY = 'REFRESH_TOKEN_CACHE_KEY';
@@ -14,7 +18,7 @@ export var REFRESH_TOKEN_CACHE_KEY = 'REFRESH_TOKEN_CACHE_KEY';
/**
* Gets a token for a given resource.
*/
-function getTokenFromCode(credentials: TnsOAuth.ITnsOAuthCredentials, code: string) : Promise {
+function getTokenFromCode(credentials: TnsOAuthModule.ITnsOAuthCredentials, code: string) : Promise {
let oauth2 = new TnsOAuth(
credentials.clientId,
credentials.clientSecret,
@@ -38,7 +42,7 @@ function getTokenFromCode(credentials: TnsOAuth.ITnsOAuthCredentials, code: stri
/**
* Gets a new access token via a previously issued refresh token.
*/
-export function getTokenFromRefreshToken(credentials: TnsOAuth.ITnsOAuthCredentials, refreshToken: string) : Promise {
+export function getTokenFromRefreshToken(credentials: TnsOAuthModule.ITnsOAuthCredentials, refreshToken: string) : Promise {
var oauth2 = new TnsOAuth(
credentials.clientId,
credentials.clientSecret,
@@ -63,7 +67,7 @@ export function getTokenFromRefreshToken(credentials: TnsOAuth.ITnsOAuthCredenti
* Generate a fully formed uri to use for authentication based on the supplied resource argument
* @return {string} a fully formed uri with which authentication can be completed
*/
-export function getAuthUrl(credentials: TnsOAuth.ITnsOAuthCredentials) : string {
+export function getAuthUrl(credentials: TnsOAuthModule.ITnsOAuthCredentials) : string {
return credentials.authority + credentials.authorizeEndpoint +
'?client_id=' + credentials.clientId +
'&response_type=code' +
@@ -78,7 +82,7 @@ export function getTokenFromCache() {
return TnsOAuthTokenCache.getToken();
}
-export function loginViaAuthorizationCodeFlow(credentials: TnsOAuth.ITnsOAuthCredentials, successPage?: string) : Promise {
+export function loginViaAuthorizationCodeFlow(credentials: TnsOAuthModule.ITnsOAuthCredentials, successPage?: string) : Promise {
return new Promise((resolve, reject) => {
var navCount = 0;
@@ -106,7 +110,7 @@ export function loginViaAuthorizationCodeFlow(credentials: TnsOAuth.ITnsOAuthCre
if (codeStr) {
try {
getTokenFromCode(credentials, codeStr)
- .then((response: TnsOAuth.ITnsOAuthTokenResult)=>{
+ .then((response: TnsOAuthModule.ITnsOAuthTokenResult)=>{
TnsOAuthTokenCache.setToken(response);
if (successPage && navCount === 0) {
let navEntry: frameModule.NavigationEntry = {
@@ -139,13 +143,13 @@ export function loginViaAuthorizationCodeFlow(credentials: TnsOAuth.ITnsOAuthCre
});
}
-export function refreshToken(credentials: TnsOAuth.ITnsOAuthCredentials) : Promise {
+export function refreshToken(credentials: TnsOAuthModule.ITnsOAuthCredentials) : Promise {
return new Promise((resolve, reject) => {
try {
let oldTokenResult = TnsOAuthTokenCache.getToken();
getTokenFromRefreshToken(credentials, oldTokenResult.refreshToken)
- .then((response: TnsOAuth.ITnsOAuthTokenResult)=>{
+ .then((response: TnsOAuthModule.ITnsOAuthTokenResult)=>{
TnsOAuthTokenCache.setToken(response);
resolve(response);
})
@@ -251,7 +255,7 @@ class TnsOAuth {
return this._baseSite + this._authorizeUrl + "?" + querystring.stringify(params);
}
- public getOAuthAccessToken(code, params) : Promise {
+ public getOAuthAccessToken(code, params) : Promise {
//console.log('called TnsOAuth.getOAuthAccessToken');
var params= params || {};
params['client_id'] = this._clientId;
@@ -267,7 +271,7 @@ class TnsOAuth {
'Content-Type': 'application/x-www-form-urlencoded'
};
- return new Promise((resolve, reject)=>{
+ return new Promise((resolve, reject)=>{
this._request("POST", this.accessTokenUrl, post_headers, post_data, null)
.then((response:http.HttpResponse)=>{
var results;
@@ -292,7 +296,7 @@ class TnsOAuth {
let expDate = new Date();
expDate.setSeconds(expDate.getSeconds() + expSecs);
- let tokenResult: TnsOAuth.ITnsOAuthTokenResult = {
+ let tokenResult: TnsOAuthModule.ITnsOAuthTokenResult = {
accessToken: access_token,
refreshToken: refresh_token,
accessTokenExpiration: expDate,
diff --git a/tsconfig.json b/tsconfig.json
index 12d3511..b39a1c6 100755
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -2,19 +2,19 @@
"compilerOptions": {
"target": "es5",
"module": "commonjs",
+ "noImplicitAny": false,
"removeComments": true,
"experimentalDecorators": true,
- "sourceMap": true,
- "noEmitHelpers": true,
- "noEmitOnError": false
+ "noLib": false,
+ "preserveConstEnums": true,
+ "declaration": false,
+ "suppressImplicitAnyIndexErrors": true
},
+ "filesGlob": [
+ "./**/*.ts",
+ "!./node_modules/**/*.ts"
+ ],
"files": [
- "demo/node_modules/tns-core-modules/tns-core-modules.d.ts",
- "demo/node_modules/tns-platform-declarations/tns-core-modules/android17.d.ts",
- "demo/typings/ios.d.ts",
- "demo/typings/url.d.ts",
- "demo/typings/querystring.d.ts",
- "tns-oauth-interfaces.d.ts",
"auth-helper.ts",
"auth-helper-facebook.ts",
"auth-helper-google.ts",
@@ -27,11 +27,13 @@
"tns-oauth-uuid.ts",
"tns-oauth-webview.ts",
"tns-oauth-webview-helper.ios.ts",
- "tns-oauth-webview-helper.android.ts"
+ "tns-oauth-webview-helper.android.ts",
+ "./typings/querystring.d.ts",
+ "./typings/url.d.ts"
],
"compileOnSave": false,
"exclude": [
"node_modules",
"platforms"
]
-}
+}
\ No newline at end of file
diff --git a/typings/querystring.d.ts b/typings/querystring.d.ts
new file mode 100644
index 0000000..12e6f0a
--- /dev/null
+++ b/typings/querystring.d.ts
@@ -0,0 +1,27 @@
+// Type definitions for query-string v3.0.0
+// Project: https://github.com/sindresorhus/query-string
+// Definitions by: Sam Verschueren
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+
+declare module "querystring" {
+ /**
+ * Parse a query string into an object.
+ * Leading ? or # are ignored, so you can pass location.search or location.hash directly.
+ * @param str
+ */
+ export function parse(str: string): any;
+
+ /**
+ * Stringify an object into a query string, sorting the keys.
+ *
+ * @param obj
+ */
+ export function stringify(obj: any, options?: {strict: boolean}): string;
+
+ /**
+ * Extract a query string from a URL that can be passed into .parse().
+ *
+ * @param str
+ */
+ export function extract(str: string): string;
+}
\ No newline at end of file
diff --git a/typings/url.d.ts b/typings/url.d.ts
new file mode 100644
index 0000000..ba57757
--- /dev/null
+++ b/typings/url.d.ts
@@ -0,0 +1,8 @@
+
+declare module "url" {
+ export function Url(): void;
+ export function parse(url: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): any;
+}
+
+
+