Class OAuthClient

java.lang.Object
x.oauth.client.OAuthClient

public class OAuthClient extends Object
OAuth 2.0 Main Services.
Author:
sakdsitt
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    deleteScope(String scopeName)
    Delete a scope DELETE /oauth20/scopes/[scope]
    static String
    Get all client application request : GET /oauth20/applications response :
    static String
    Get all registered scopes
    static String
    Get info about a client application by clientId request : GET /oauth20/applications/[client_id] response : {"name":[client_app_name],"description":[description],"scope":[scope],"registered":[registration_date]},"redirect_uri":[redirect_uri]
    static String
    getAuthCode(String clientId, String redirectURI, String responseType, String scope)
    1.
    static String
    Get registered scopes by ClientID request : GET /oauth20/scopes?
    static String
    Get registered scopes by Scope name
    static String
    getTokenAuthCode(String code, String redirect_uri, String client_id, String client_secret)
    The second step to issue an access token is to use the authorization code returned in the response of the step 1.
    static String
    getTokenClient(String client_id, String client_secret, String scope)
    2.
    static String
    getTokenRefresh(String client_id, String client_secret, String refresh_token, String scope)
    4.
    static String
    getTokenResource(String client_id, String client_secret, String username, String password, String scope)
    3.
    static th.co.skylogicsystem.skyframework.core.utils.webservice.WebServiceManager
     
    static void
    main(String[] args)
     
    static String
    registerApp(String name, String description, String scope, String redirect_uri)
    Register a client application POST /oauth20/applications Content-Type: application/json {"name":[client application name],"description":[description],"scope":[scope], "redirect_uri":[redirect uri], "details":[refresh tokens expiration time in second],"client_id":[client id],"client_secret":[client secret]} POST http://127.0.0.1:8080/oauth20/applications Content-Type: application/json { "name": "test_app", "description": "test client app", "scope": "test_scope", "redirect_uri": "http://127.0.0.1:8080"
    static String
    registerScope(String scope, String description, String cc_expires_in, String pass_expires_in)
    Register a new scope
    static String
    updateApp(String clientId, String jsonUpdateApp)
    Update a client application PUT /oauth20/applications/[client_id] PUT http://127.0.0.1:8080/oauth20/applications/b9db6d84dc98a895035e68f972e30503d3c724c8 Content-Type: application/json { "description": "updated description", "scope": "test_scope", "application_details": { "division": "IT", "organization": "MM" } } Activate/Deactivate a client application PUT /oauth20/applications/[client_ id] PUT http://127.0.0.1:8080/oauth20/applications/b9db6d84dc98a895035e68f972e30503d3c724c8 Content-Type: application/json {"status":1}
    static String
    updateScope(String scopeName, String jsonUpdateScope)
    Update scope PUT /oauth20/scopes/[scope] Content-Type: application/json {"description":[description],"cc_expires_in":[client credentials tokens expiration time in seconds], "pass_expires_in":[password tokens expiration time in seconds], "refresh_expires_in":[refresh tokens expiration time in second]} PUT http://127.0.0.1:8080/oauth20/scopes Content-Type: application/json {"description":"new basic scope description"}

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • init

      public static th.co.skylogicsystem.skyframework.core.utils.webservice.WebServiceManager init()
    • registerScope

      public static String registerScope(String scope, String description, String cc_expires_in, String pass_expires_in) throws IOException
      Register a new scope
      Throws:
      IOException
    • getAllScope

      public static String getAllScope() throws IOException
      Get all registered scopes
      Throws:
      IOException
    • getScopeByName

      public static String getScopeByName(String scopeName) throws IOException
      Get registered scopes by Scope name
      Throws:
      IOException
    • getScopeByClientId

      public static String getScopeByClientId(String clientId) throws IOException
      Get registered scopes by ClientID request : GET /oauth20/scopes?client_id=xxx response : [{"scope":[scope_name],"description":[description],"cc_expires_in":[cc_expires_in],"pass_expires_in":[pass_expires_in]},...]
      Throws:
      IOException
    • updateScope

      public static String updateScope(String scopeName, String jsonUpdateScope) throws IOException
      Update scope PUT /oauth20/scopes/[scope] Content-Type: application/json {"description":[description],"cc_expires_in":[client credentials tokens expiration time in seconds], "pass_expires_in":[password tokens expiration time in seconds], "refresh_expires_in":[refresh tokens expiration time in second]} PUT http://127.0.0.1:8080/oauth20/scopes Content-Type: application/json {"description":"new basic scope description"}
      Throws:
      IOException
    • deleteScope

      public static String deleteScope(String scopeName) throws IOException
      Delete a scope DELETE /oauth20/scopes/[scope]
      Throws:
      IOException
    • registerApp

      public static String registerApp(String name, String description, String scope, String redirect_uri) throws IOException
      Register a client application POST /oauth20/applications Content-Type: application/json {"name":[client application name],"description":[description],"scope":[scope], "redirect_uri":[redirect uri], "details":[refresh tokens expiration time in second],"client_id":[client id],"client_secret":[client secret]} POST http://127.0.0.1:8080/oauth20/applications Content-Type: application/json { "name": "test_app", "description": "test client app", "scope": "test_scope", "redirect_uri": "http://127.0.0.1:8080"
      Throws:
      IOException
    • updateApp

      public static String updateApp(String clientId, String jsonUpdateApp) throws IOException
      Update a client application PUT /oauth20/applications/[client_id] PUT http://127.0.0.1:8080/oauth20/applications/b9db6d84dc98a895035e68f972e30503d3c724c8 Content-Type: application/json { "description": "updated description", "scope": "test_scope", "application_details": { "division": "IT", "organization": "MM" } } Activate/Deactivate a client application PUT /oauth20/applications/[client_ id] PUT http://127.0.0.1:8080/oauth20/applications/b9db6d84dc98a895035e68f972e30503d3c724c8 Content-Type: application/json {"status":1}
      Throws:
      IOException
    • getAllApps

      public static String getAllApps() throws IOException
      Get all client application request : GET /oauth20/applications response :
      Throws:
      IOException
    • getAppByClientId

      public static String getAppByClientId(String clientId) throws IOException
      Get info about a client application by clientId request : GET /oauth20/applications/[client_id] response : {"name":[client_app_name],"description":[description],"scope":[scope],"registered":[registration_date]},"redirect_uri":[redirect_uri]
      Throws:
      IOException
    • getAuthCode

      public static String getAuthCode(String clientId, String redirectURI, String responseType, String scope) throws IOException
      1. Authorization code flow first step, obtaining an authorization code
      Throws:
      IOException
    • getTokenAuthCode

      public static String getTokenAuthCode(String code, String redirect_uri, String client_id, String client_secret) throws IOException
      The second step to issue an access token is to use the authorization code returned in the response of the step 1.
      Throws:
      IOException
    • getTokenClient

      public static String getTokenClient(String client_id, String client_secret, String scope) throws IOException
      2. Client credentials grant type Obtain a client credentials access token
      Throws:
      IOException
    • getTokenResource

      public static String getTokenResource(String client_id, String client_secret, String username, String password, String scope) throws IOException
      3. Resource owner password credentials grant Access tokens with grant type client credentials are obtained by posting a request to /oauth20/tokens with grant_type=password. Here is an example request:
      Throws:
      IOException
    • getTokenRefresh

      public static String getTokenRefresh(String client_id, String client_secret, String refresh_token, String scope) throws IOException
      4. Refresh token grant type Access tokens with grant type client credentials are obtained by posting a request to /oauth20/tokens with grant_type=refresh_token. Here is an example request:
      Throws:
      IOException
    • main

      public static void main(String[] args)