Commit 63a9b904 authored by laurent l's avatar laurent l

IOS: OAuth

parent 391273a2
This diff is collapsed.
import {Account, Cookies} from '../../models';
import {WebView} from 'ui/web-view';
import { Account, Cookies } from '../../models';
import { WebView } from 'ui/web-view';
export class OAuthWebViewClient {
protected static _onTokenSet: any;
protected static _onError: any;
protected _view: WebView;
public constructor(view:WebView) {
public static newWithWebView(webview: WebView): OAuthWebViewClient {
return new OAuthWebViewClient(webview);
}
public constructor(view: WebView) {
this._view = view;
let WVClient = (<any>android.webkit.WebViewClient).extend({
shouldOverrideUrlLoading: (_webview, page_url) => {
if (typeof page_url === 'object') // android 7.1.1 compatibility
......@@ -16,8 +21,8 @@ export class OAuthWebViewClient {
let matches = page_url.match(/.*token=(.*)$/);
if (matches) {
let token = matches[1];
OAuthWebViewClient._onTokenSet(token);
let token = matches[1];
OAuthWebViewClient._onTokenSet(token);
new Cookies().clearCookies();
return true;
}
......@@ -27,14 +32,15 @@ export class OAuthWebViewClient {
return true;
}
return false;
return false;
},
onPageFinished: (_webview, page_url) => {
},
onPageStarted: (_webview, page_url, favicon) => {
}});
}
});
this._view.android.setWebViewClient(new WVClient());
}
......@@ -48,9 +54,9 @@ export class OAuthWebViewClient {
OAuthWebViewClient._onError = reject;
this._view.src = account.getUrl()
+ '/auth/oauth/response_type/code/id_profil/1/client_id/'
+ L('app_name')
+ '?redirect_uri=bibapp://authorize';
+ '/auth/oauth/response_type/code/id_profil/1/client_id/'
+ L('app_name')
+ '?redirect_uri=bibapp://authorize';
});
}
}
import {Account} from '../../models';
import { Account } from '../../models';
import { WebView } from 'ui/web-view';
export declare class OAuthWebViewClient {
public constructor(view:WebView);
public login(account: Account): Promise<string>;
public static newWithWebView(webview: WebView): OAuthWebViewClient;
public login(account: Account): Promise<string>;
}
import {Account} from '../../models';
import {WebView} from 'ui/web-view';
import { Account, Cookies } from '../../models';
import { WebView } from 'ui/web-view';
var NSWKNavigationDelegate = (NSObject as any).extend(
{
_owner: null,
_origDelegate: null,
_onTokenSet: null,
_onError: null,
webViewDidStartLoad: function(webview: WKWebView) {
console.log('start Load');
return this._origDelegate.webViewDidStartLoad(webview);
},
webViewDidStartProvisionalNavigation: function(webview, navigation) {
console.log('start prov url:' + webview.URL.absoluteString);
return this._origDelegate.webViewDidStartProvisionalNavigation(webview, navigation);
},
webViewDidFailNavigationWithError: function(webview: WKWebView, navigation: WKNavigation, error: NSError) {
console.log('didFailNavigationWithError');
return this._origDelegate.webViewDidFailNavigationWithError(webview, navigation, error);
},
webViewDecidePolicyForNavigationActionDecisionHandler: function(webview: WKWebView, navigationAction: WKNavigationAction, decisionHandler: WKNavigationActionPolicy) {
console.log('decidePolicyForNavigationActionDecisionHandler:' + webview.URL.absoluteString);
let page_url = webview.URL.absoluteString;
let matches = page_url.match(/.*token=(.*)$/);
if (matches) {
let token = matches[1];
this._onTokenSet(token);
new Cookies().clearCookies();
}
return this._origDelegate.webViewDecidePolicyForNavigationActionDecisionHandler(webview, navigationAction, decisionHandler);
},
webViewShouldStartLoadWithRequestNavigationType: function(webview: WKWebView, request: NSURLRequest, navigationType: number) {
console.log('start loading');
return this._origDelegate.webViewShouldStartLoadWithRequestNavigationType(webview, request, navigationType);
},
},
{
name: 'NSWKNavigationDelegate',
protocols: [WKNavigationDelegate]
}
);
NSWKNavigationDelegate.ObjCProtocols = [WKNavigationDelegate];
export class OAuthWebViewClient {
protected _view: WebView
public constructor(view:WebView) {
this._view = view
protected _view: WebView;
public static newWithWebView(webview: WebView): OAuthWebViewClient {
return new OAuthWebViewClient(webview);
}
public constructor(view: WebView) {
this._view = view;
}
public login(account: Account): Promise<string> {
new Cookies().clearCookies();
let delegate = new NSWKNavigationDelegate();
delegate._owner = new WeakRef(this._view);
delegate._origDelegate = (<any>this._view)._delegate;
(<any>this._view)._delegate = delegate;
(<any>this._view).ios.navigationDelegate = delegate;
return new Promise((resolve, reject) => {
let url = account.getUrl()
+ 'auth/oauth/response_type/code/id_profil/1/client_id/'
+ L('app_name')
+ '?redirect_uri=bibapp://authorize'
console.log(url)
this._view.src = url
})
delegate._onTokenSet = resolve;
delegate._onError = reject;
this._view.src = account.getUrl()
+ '/auth/oauth/response_type/code/id_profil/1/client_id/'
+ L('app_name')
+ '?redirect_uri=bibapp://authorize';
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment