Skip to content

Instantly share code, notes, and snippets.

@dixonsiu
Last active February 26, 2019 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dixonsiu/f0ebacefc53a4f63c38d438d9509031d to your computer and use it in GitHub Desktop.
Save dixonsiu/f0ebacefc53a4f63c38d438d9509031d to your computer and use it in GitHub Desktop.
Tokenの説明

Cell認証Token

  1. HomeAppにログイン時取得したユーザー token

     $.ajax({
         type: "POST",
         url: lg.rootUrl + '__token',
         processData: true,
         dataType: 'json',
         data: {
              grant_type: "password",
              username: username,
              password: pw,
              p_cookie: true
         },
         headers: {
             'Accept':'application/json',
             'content-type': 'application/x-www-form-urlencoded'
         }
     })
    

アプリ処理から自セル内該当Boxの内容を見る

  1. User Cell & refresh token -> App HomeApp (cm.execApp)

  2. App認証token // Get App Authentication Token

    • Engine Script方法(お勧め)

        Common.getAppAuthToken = function(cellUrl) {
            let engineEndPoint = getEngineEndPoint();
            return $.ajax({
                type: "POST",
                url: engineEndPoint,
                data: {
                        p_target: cellUrl
                },
                headers: {'Accept':'application/json'}
            });
        };
      
    • 実際REST API (AJAX)方法

        $.ajax({
            type: "POST",
            url: Common.getAppCellUrl() + '__token',
            processData: true,
            dataType: 'json',
            data: {
                grant_type: "password",
                username: personalInfo.appTokenId,
                password: personalInfo.appTokenPw,
                p_target: Common.getCellUrl()
            },
            headers: {'Accept':'application/json'}
        });
      
  3. Appに認証された自分用のtoken(Schema認証token)

     $.ajax({
         type: "POST",
         url: cellUrl + '__token',
         processData: true,
         dataType: 'json',
         data: {
             grant_type: "refresh_token",
             refresh_token: Common.accessData.refToken, // HomeAppから貰ったのrefresh_token
             client_id: Common.getAppCellUrl(),
             client_secret: appToken //App認証tokenのaccess_token
         },
         headers: {'Accept':'application/json'}
     });
    

アプリ処理から他セル内該当Boxの内容を見る

  1. Transcell Tokenを取得

     return $.ajax({
         type: "POST",
         url: Common.getCellUrl() + '__token', // 自分Cell URL
         processData: true,
         dataType: 'json',
         data: {
             grant_type: "refresh_token",
             refresh_token: Common.getRefressToken(), // 自分のrefresh token
             p_target: extCellUrl  // 他人のURL
         },
         headers: {'Accept':'application/json'}
     });
    
  2. 他人のApp認証token
    // Get App Authentication Token

    • Engine Script方法(お勧め)

        Common.getAppAuthToken = function(cellUrl) {
            let engineEndPoint = getEngineEndPoint();
            return $.ajax({
                type: "POST",
                url: engineEndPoint,
                data: {
                        p_target: cellUrl  // 他人のURL
                },
                headers: {'Accept':'application/json'}
            });
        };
      
  3. 他人のAppに認証された自分用のtoken(Schema認証token)

     $.ajax({
             type: "POST",
             url: cellUrl + '__token',  // 他人のURL
             processData: true,
             dataType: 'json',
             data: {
                 grant_type: 'urn:ietf:params:oauth:grant-type:saml2-bearer',
                 assertion: tcat,
                 client_id: Common.getAppCellUrl(),
                 client_secret: aaat
             },
             headers: {'Accept':'application/json'}
         });
    

インストールされたAppのBoxの内部をアクセスため

  1. Box URL取得
    例) https://demo.personium.io/dixonsiu/app-myboard
    例) https://demo.personium.io/hoge/io_personium_demo_app-myboard

     Common.getBoxUrlAPI = function(cellUrl, token) {
         return $.ajax({
             type: "GET",
             url: cellUrl + "__box",
             headers: {
                 'Authorization':'Bearer ' + token,
                 'Accept':'application/json'
             }
         });
     };
    
  2. 取得したBox URLを使う
    「/MyBoardBox/my-board.json」 Barファイルの指定。   例) https://demo.personium.io/dixonsiu/app-myboard/MyBoardBox/my-board.json
    例) https://demo.personium.io/hoge/io_personium_demo_app-myboard/MyBoardBox/my-board.json

     Common.getAppDataAPI = function(targetBoxUrl, token) {
         let requestInfo = $.extend(true,
             {
                 type: 'GET',
                 url: targetBoxUrl + getAppDataPath(),
                 headers: {
                         'Authorization':'Bearer ' + token,
                 }
             },
             getAppRequestInfo()
         );
    
         return $.ajax(requestInfo);
     };
    

他人の他人の

  1. #他人のものを見る を実施。 A -> B
  2. 他人の外部セル(extCell)
    B -> C, D
  3. 上記のセルに #他人のものを見る を実施。
    A -> C, D
@takky0330
Copy link

これ、いいですねぇ…
次回の勉強会は、これについてイロイロお聞きしたいと思います!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment