Skip to content

Webview settings intercept #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions auth-helper-salesforce.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ export class AuthHelperSalesforce extends AuthHelper implements TnsOAuth.ITnsAut
redirectUri: string,
responseType: string,
scope: Array<string>,
clientSecret?: string,
webviewSettingsIntercept?: (WebView) => void
) {
super();
var scopeStr = scope.join('%20');
@@ -28,11 +28,11 @@ export class AuthHelperSalesforce extends AuthHelper implements TnsOAuth.ITnsAut
tokenEndpoint: '/services/oauth2/token',
revokeEndpoint: '/services/oauth2/revoke',
clientId: clientId,
clientSecret: clientSecret,
redirectUri: redirectUri,
responseType: responseType,
scope: scopeStr
};
this._webviewSettingsIntercept = webviewSettingsIntercept;
}
//Gets cookie domains for logging out
public logout(): Promise<void> {
3 changes: 2 additions & 1 deletion auth-helper.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import * as tnsOauth from './tns-oauth';
import * as TnsOAuth from './tns-oauth-interfaces';

export class AuthHelper {
protected _webviewSettingsIntercept: (WebView) => void;
public credentials: TnsOAuth.ITnsOAuthCredentials;
public tokenResult: TnsOAuth.ITnsOAuthTokenResult;

@@ -13,7 +14,7 @@ export class AuthHelper {

public login(successPage?: string): Promise<string> {
return new Promise((resolve, reject) => {
tnsOauth.loginViaAuthorizationCodeFlow(this.credentials, successPage)
tnsOauth.loginViaAuthorizationCodeFlow(this.credentials, this._webviewSettingsIntercept, successPage)
.then((response: TnsOAuth.ITnsOAuthTokenResult) => {
this.tokenResult = response;
resolve(response.accessToken);
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -115,7 +115,8 @@ export function initSalesforce(options: TnsOAuth.ITnsOAuthOptionsSalesforce): Pr
options.clientId,
options.redirectUri,
options.responseType,
options.scope
options.scope,
options.webviewSettingsIntercept
);
resolve(instance);
} catch (ex) {
1 change: 1 addition & 0 deletions tns-oauth-interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -67,4 +67,5 @@ export interface ITnsOAuthOptionsSalesforce extends ITnsOAuthOptions {
authority: string;
redirectUri: string;
responseType: string;
webviewSettingsIntercept: (WebView) => void;
}
5 changes: 4 additions & 1 deletion tns-oauth.ts
Original file line number Diff line number Diff line change
@@ -101,11 +101,14 @@ export function getTokenFromCache() {
return TnsOAuthTokenCache.getToken();
}

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

let checkCodeIntercept = (webView, error, url): boolean => {
webviewSettingsIntercept(webView);
var retStr = '';
try {
if (error && error.userInfo && error.userInfo.allValues && error.userInfo.allValues.count > 0) {