Skip to content

Commit

Permalink
Updated typescript definitions and references
Browse files Browse the repository at this point in the history
  • Loading branch information
alexziskind1 committed Aug 23, 2016
1 parent 801d05f commit 6140ecc
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 87 deletions.
11 changes: 10 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
demo/
node_modules/
hooks/
*.png
*.log
*.log
*.ts
*.js.map
tsconfig.json

!index.d.ts
!tns-oauth-interfaces.d.ts
!*.js
3 changes: 3 additions & 0 deletions auth-helper-facebook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/// <reference path="references.d.ts" />

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 {

Expand Down
3 changes: 3 additions & 0 deletions auth-helper-google.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/// <reference path="references.d.ts" />

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 {

Expand Down
3 changes: 3 additions & 0 deletions auth-helper-office365.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/// <reference path="references.d.ts" />

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 {

Expand Down
3 changes: 2 additions & 1 deletion auth-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference path="./tns-oauth-interfaces.d.ts" />
/// <reference path="references.d.ts" />

import * as tnsOauth from './tns-oauth';
import * as TnsOAuth from './tns-oauth-interfaces';

export class AuthHelper {
public credentials: TnsOAuth.ITnsOAuthCredentials;
Expand Down
23 changes: 11 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/// <reference path="demo/node_modules/tns-core-modules/es6-promise.d.ts" />
/// <reference path="./tns-oauth-interfaces.d.ts" />

declare module "nativescript-oauth" {
export function initOffice365(options: TnsOAuth.ITnsOAuthOptionsOffice365): Promise<any>;
export function initFacebook(options: TnsOAuth.ITnsOAuthOptionsFacebook): Promise<any>;
export function initGoogle(options: TnsOAuth.ITnsOAuthOptionsGoogle): Promise<any>;
import * as TnsOAuth from './tns-oauth-interfaces';
export * from './tns-oauth-interfaces';

export function accessToken() : string;
export function login(successPage?: string) : Promise<string>;
export function logout(successPage: string) : Promise<any>;
export function accessTokenExpired() : boolean;
export function ensureValidToken() : Promise<string>;
}
export declare var instance: TnsOAuth.ITnsAuthHelper;
export declare function initOffice365(options: TnsOAuth.ITnsOAuthOptionsOffice365): Promise<any>;
export declare function initFacebook(options: TnsOAuth.ITnsOAuthOptionsFacebook): Promise<any>;
export declare function initGoogle(options: TnsOAuth.ITnsOAuthOptionsGoogle): Promise<any>;
export declare function accessToken(): string;
export declare function login(successPage?: string): Promise<string>;
export declare function logout(successPage: string): Promise<any>;
export declare function accessTokenExpired(): boolean;
export declare function ensureValidToken(): Promise<string>;

5 changes: 5 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/// <reference path="references.d.ts" />



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;

Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -20,6 +20,10 @@
"type": "git",
"url": "https://github.com/alexziskind1/nativescript-oauth.git"
},
"typescript": {
"definition": "index.d.ts"
},
"typings": "index",
"keywords": [
"NativeScript",
"JavaScript",
Expand All @@ -33,13 +37,13 @@
"author": {
"name": "Alexander Ziskind",
"email": "[email protected]",
"url" : "http://www.nuvious.com/blog"
"url": "http://www.nuvious.com/blog"
},
"contributors": [
{
"name": "Kevin Primm",
"email": "[email protected]",
"url" : "http://primm.me/"
"url": "https://github.com/kfprimm"
}
],
"bugs": {
Expand All @@ -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"
}
}
8 changes: 7 additions & 1 deletion references.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" /> Needed for autocompletion and compilation.
/// <reference path="demo/node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="demo/node_modules/tns-platform-declarations/tns-core-modules/android17.d.ts" />
/// <reference path="demo/node_modules/tns-platform-declarations/tns-core-modules/ios.d.ts" />
/// <reference path="demo/node_modules/tns-platform-declarations/tns-core-modules/org.nativescript.widgets.d.ts" />
/// <reference path="./index.d.ts" />
/// <reference path="./typings/url.d.ts" />
/// <reference path="./typings/querystring.d.ts" />
86 changes: 43 additions & 43 deletions tns-oauth-interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@

declare module TnsOAuth {
interface ITnsAuthHelper {
credentials: ITnsOAuthCredentials;
tokenResult: ITnsOAuthTokenResult;
login: (successPage?: string) => Promise<string>;
logout: (successPage: string) => Promise<{}>;
refreshToken: () => Promise<string>;
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<string>;
logout: (successPage: string) => Promise<{}>;
refreshToken: () => Promise<string>;
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 {
}
4 changes: 3 additions & 1 deletion tns-oauth-page-provider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// <reference path="references.d.ts" />

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';


Expand Down
4 changes: 4 additions & 0 deletions tns-oauth-token-cache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// <reference path="references.d.ts" />

import * as TnsOAuth from './tns-oauth-interfaces';

import * as applicationSettingsModule from "application-settings";

const TNS_OAUTH_KEY = "TNS_OAUTH_KEY";
Expand Down
2 changes: 2 additions & 0 deletions tns-oauth-webview-helper.android.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path="references.d.ts" />

import { WebView } from 'ui/web-view';
import trace = require("trace");

Expand Down
2 changes: 2 additions & 0 deletions tns-oauth-webview-helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path="references.d.ts" />

import { WebView } from 'ui/web-view';

export declare class TnsOAuthWebViewHelper {
Expand Down
2 changes: 2 additions & 0 deletions tns-oauth-webview-helper.ios.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path="references.d.ts" />

import { WebView } from 'ui/web-view';

export class TnsOAuthWebViewHelper extends NSObject implements UIWebViewDelegate {
Expand Down
2 changes: 2 additions & 0 deletions tns-oauth-webview.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path="references.d.ts" />

import { WebView } from 'ui/web-view';

export class TnsOAuthWebViewDelegateImpl extends NSObject implements UIWebViewDelegate {
Expand Down
24 changes: 14 additions & 10 deletions tns-oauth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// <reference path="references.d.ts" />


import * as querystring from 'querystring';
import * as URL from 'url';
import * as http from 'http';
Expand All @@ -7,14 +10,15 @@ 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';

/**
* Gets a token for a given resource.
*/
function getTokenFromCode(credentials: TnsOAuth.ITnsOAuthCredentials, code: string) : Promise<TnsOAuth.ITnsOAuthTokenResult> {
function getTokenFromCode(credentials: TnsOAuthModule.ITnsOAuthCredentials, code: string) : Promise<TnsOAuthModule.ITnsOAuthTokenResult> {
let oauth2 = new TnsOAuth(
credentials.clientId,
credentials.clientSecret,
Expand All @@ -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<TnsOAuth.ITnsOAuthTokenResult> {
export function getTokenFromRefreshToken(credentials: TnsOAuthModule.ITnsOAuthCredentials, refreshToken: string) : Promise<TnsOAuthModule.ITnsOAuthTokenResult> {
var oauth2 = new TnsOAuth(
credentials.clientId,
credentials.clientSecret,
Expand All @@ -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' +
Expand All @@ -78,7 +82,7 @@ export function getTokenFromCache() {
return TnsOAuthTokenCache.getToken();
}

export function loginViaAuthorizationCodeFlow(credentials: TnsOAuth.ITnsOAuthCredentials, successPage?: string) : Promise<TnsOAuth.ITnsOAuthTokenResult> {
export function loginViaAuthorizationCodeFlow(credentials: TnsOAuthModule.ITnsOAuthCredentials, successPage?: string) : Promise<TnsOAuthModule.ITnsOAuthTokenResult> {
return new Promise((resolve, reject) => {
var navCount = 0;

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -139,13 +143,13 @@ export function loginViaAuthorizationCodeFlow(credentials: TnsOAuth.ITnsOAuthCre
});
}

export function refreshToken(credentials: TnsOAuth.ITnsOAuthCredentials) : Promise<TnsOAuth.ITnsOAuthTokenResult> {
export function refreshToken(credentials: TnsOAuthModule.ITnsOAuthCredentials) : Promise<TnsOAuthModule.ITnsOAuthTokenResult> {
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);
})
Expand Down Expand Up @@ -251,7 +255,7 @@ class TnsOAuth {
return this._baseSite + this._authorizeUrl + "?" + querystring.stringify(params);
}

public getOAuthAccessToken(code, params) : Promise<TnsOAuth.ITnsOAuthTokenResult> {
public getOAuthAccessToken(code, params) : Promise<TnsOAuthModule.ITnsOAuthTokenResult> {
//console.log('called TnsOAuth.getOAuthAccessToken');
var params= params || {};
params['client_id'] = this._clientId;
Expand All @@ -267,7 +271,7 @@ class TnsOAuth {
'Content-Type': 'application/x-www-form-urlencoded'
};

return new Promise<TnsOAuth.ITnsOAuthTokenResult>((resolve, reject)=>{
return new Promise<TnsOAuthModule.ITnsOAuthTokenResult>((resolve, reject)=>{
this._request("POST", this.accessTokenUrl, post_headers, post_data, null)
.then((response:http.HttpResponse)=>{
var results;
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 6140ecc

Please sign in to comment.