1- QUnit . test ( "hello test" , function ( assert ) {
2- assert . ok ( 1 == "1" , "Passed!" ) ;
1+
2+
3+ var config = {
4+ providerID : "google" ,
5+ client_id : "541950296471.apps.googleusercontent.com" ,
6+ redirect_uri : "http://bridge.uninett.no/jso/index.html" ,
7+ authorization : "https://accounts.google.com/o/oauth2/auth" ,
8+ scopes : { request : [ "https://www.googleapis.com/auth/userinfo.profile" ] } ,
9+ debug :true
10+ } ;
11+
12+
13+ var RedirectCatcher = function ( ) {
14+ var that = this ;
15+ this . callback = null ;
16+ this . url = null ;
17+ setTimeout ( function ( ) {
18+ if ( that . url === null ) {
19+ if ( typeof that . callback === 'function' ) {
20+ that . callback ( null ) ;
21+ }
22+ }
23+ } , 2000 ) ;
24+ } ;
25+ RedirectCatcher . prototype . onRedirect = function ( callback ) {
26+ this . callback = callback ;
27+ } ;
28+ RedirectCatcher . prototype . redirect = function ( url ) {
29+ console . log ( "RedirectCatcherreceived redirect to " , url ) ;
30+ this . url = url ;
31+ if ( typeof this . callback === 'function' ) {
32+ this . callback ( this . url ) ;
33+ } else {
34+ console . error ( "Callback was not defined" ) ;
35+ }
36+ } ;
37+
38+
39+ QUnit . test ( "JSO Loaded" , function ( assert ) {
40+ console . log ( "JSO" , JSO ) ;
41+ assert . ok ( typeof JSO === 'function' , "JSO successfully loaded." ) ;
42+ assert . ok ( 1 == "1" , "Passed!" ) ;
43+
44+ } ) ;
45+ QUnit . test ( "JSO Authorization redirect" , function ( assert ) {
46+ var done = assert . async ( ) ;
47+ var r = new RedirectCatcher ( ) ;
48+ r . onRedirect ( function ( url ) {
49+ assert . ok ( url !== null , 'Redirect was performed' ) ;
50+ console . log ( "Redirect to " , url ) ;
51+ done ( ) ;
52+ } ) ;
53+
54+ var jso = new JSO ( config ) ;
55+ jso . on ( 'redirect' , function ( url ) {
56+ r . redirect ( url ) ;
57+ } ) ;
58+
59+ jso . getToken ( function ( token ) {
60+
61+ console . log ( "I got the token: " , token ) ;
62+
63+ } , { } ) ;
64+
65+
366} ) ;
0 commit comments