{"id":9544,"date":"2024-10-31T17:16:27","date_gmt":"2024-10-31T08:16:27","guid":{"rendered":"https:\/\/www.auctionpro.co.kr\/?p=9544"},"modified":"2024-10-31T17:19:55","modified_gmt":"2024-10-31T08:19:55","slug":"access-token","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=9544","title":{"rendered":"Access Token"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>\uc124\uba85<\/strong>:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Access Token \uc694\uccad: \ud074\ub77c\uc774\uc5b8\ud2b8 (\uc571)\uc5d0\uc11c \uc0ac\uc6a9\uc790 \uc790\uaca9 \uc99d\uba85(\uc0ac\uc6a9\uc790 \uc774\ub984, \ube44\ubc00\ubc88\ud638)\uacfc \ud568\uaed8 client_id, client_secret\uc744 \uc0ac\uc6a9\ud558\uc5ec \uc778\uc99d \uc11c\ubc84\uc5d0 \ud1a0\ud070 \uc694\uccad\uc744 \ubcf4\ub0c5\ub2c8\ub2e4. \uc774 \uc694\uccad\uc740 HTTP POST \ubc29\uc2dd\uc73c\ub85c \uc804\uc1a1\ub429\ub2c8\ub2e4.<\/li>\n\n\n\n<li>\uc0ac\uc6a9\uc790 \uc778\uc99d: \uc778\uc99d \uc11c\ubc84\uc5d0\uc11c \uc0ac\uc6a9\uc790\uc758 \uc790\uaca9 \uc99d\uba85\uc744 \uac80\uc99d\ud569\ub2c8\ub2e4. \uc774 \uacfc\uc815\uc5d0\uc11c \uc0ac\uc6a9\uc790 \uc774\ub984\uacfc \ube44\ubc00\ubc88\ud638\uc758 \uc720\ud6a8\uc131\uc744 \ud655\uc778\ud569\ub2c8\ub2e4.<\/li>\n\n\n\n<li>Access Token\ubc1c\uae09: \uc790\uaca9 \uc99d\uba85\uc774 \uc720\ud6a8\ud558\uba74, \uc11c\ubc84\ub294 \ud074\ub77c\uc774\uc5b8\ud2b8\uc5d0\uac8c access_token(\uc561\uc138\uc2a4 \ud1a0\ud070)\uc744 \ubc1c\uae09\ud569\ub2c8\ub2e4. \uc774 \ud1a0\ud070\uc740 \uc778\uc99d\ub41c \uc0ac\uc6a9\uc790\ub97c \ub300\uc2e0\ud558\uc5ec API\uc5d0 \uc811\uadfc\ud558\ub294 \ub370 \uc0ac\uc6a9\ub429\ub2c8\ub2e4.<\/li>\n\n\n\n<li>\ud1a0\ud070 \uc218\uc2e0: \ud074\ub77c\uc774\uc5b8\ud2b8\ub294 \ubc1c\uae09\ub41c access_token\uc744 \uc218\uc2e0\ud558\uace0, \uc774\ud6c4 \uc774\ub97c \uc0ac\uc6a9\ud558\uc5ec \ubcf4\ud638\ub41c \ub9ac\uc18c\uc2a4\uc5d0 \uc811\uadfc\ud560 \uc218 \uc788\uac8c \ub429\ub2c8\ub2e4.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\uc8fc\uc694 \uad6c\uc131 \uc694\uc18c:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Client (App)<\/strong>: \ud1a0\ud070\uc744 \uc694\uccad\ud558\ub294 \uc560\ud50c\ub9ac\ucf00\uc774\uc158.<\/li>\n\n\n\n<li><strong>Authorization Server<\/strong>: \uc0ac\uc6a9\uc790 \uc778\uc99d \ubc0f \ud1a0\ud070 \ubc1c\uae09\uc744 \ub2f4\ub2f9\ud558\ub294 \uc11c\ubc84.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\uc774\ub7ec\ud55c \ud750\ub984\uc744 \uae30\ubc18\uc73c\ub85c \uc561\uc138\uc2a4 \ud1a0\ud070\uc774 \ubc1c\uae09\ub418\uba70, \uc774\ud6c4 \ud1a0\ud070\uc744 \uc774\uc6a9\ud574 \ubcf4\ud638\ub41c \ub9ac\uc18c\uc2a4(API)\uc5d0 \uc811\uadfc\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/asardana.com\/wp-content\/uploads\/2023\/01\/image-1.png?w=1024\" alt=\"\" style=\"width:768px;height:558px\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Endpoint  :  https:\/\/mytoken*********.com\/test\/token<\/li>\n\n\n\n<li>SessionTimeout   :  \uc11c\ubc84 \uc138\ud305\uc5d0 \ub530\ub77c <\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\uc694\uccad\uc5d0 \ud3ec\ud568\ub420 Data \uc608\uc2dc<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>grant_type : &#8220;password&#8221; (\uace0\uc815)<\/li>\n\n\n\n<li>username :  \uc81c\uacf5\ub41c userName  (\uc608 : T11111111)<\/li>\n\n\n\n<li>password :  \uc81c\uacf5\ub41c Passwd   (\uc608 :  PNNNNN)<\/li>\n\n\n\n<li>client_id :  \uc81c\uacf5\ub41c id  (\uc608 : pp-xxxxxxxxxxxxxxxxxxxxxxxxx1)<\/li>\n\n\n\n<li>client_secret :  \uc81c\uacf5\ub41c secret ( \uc608 : 29aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae)<\/li>\n\n\n\n<li>scope : &#8220;openid&#8221; (\uace0\uc815)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Response Token <\/h3>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" >eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwianRpIjoibWJ2YTBpNnNub3JoIn0..\n.............................................................................\n.............................................................................\n.............................................................................\n.............................................................................\n.............................................................................\n.............................................................................\n.............................................................................\n.............................................................................<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">C# <\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \">using System;\nusing System.Net.Http;\nusing System.Threading.Tasks;\nusing System.Collections.Generic;\nusing Newtonsoft.Json;\n\npublic class TokenService\n{\n    private static readonly string tokenEndpoint = \"https:\/\/mytoken*********.com\/test\/token\";\n    private static readonly string clientId = \"your_client_id\";\n    private static readonly string clientSecret = \"your_client_secret\";\n    private static readonly string username = \"your_username\";\n    private static readonly string password = \"your_password\";\n\n    public async Task&lt;string&gt; GetNDCToken()\n    {\n        using (var client = new HttpClient())\n        {\n            \/\/ \uc694\uccad\uc5d0 \ud3ec\ud568\ub420 \ud3fc \ub370\uc774\ud130 \uc900\ube44\n            var requestData = new Dictionary&lt;string, string&gt;\n            {\n                { \"grant_type\", \"password\" },\n                { \"username\", username },\n                { \"password\", password },\n                { \"client_id\", clientId },\n                { \"client_secret\", clientSecret },\n                { \"scope\", \"openid\" }\n            };\n\n            var content = new FormUrlEncodedContent(requestData);\n\n            \/\/ POST \uc694\uccad \uc804\uc1a1\n            var response = await client.PostAsync(tokenEndpoint, content);\n\n            \/\/ \uc751\ub2f5\uc774 \uc131\uacf5\uc801\uc778\uc9c0 \ud655\uc778\n            if (response.IsSuccessStatusCode)\n            {\n                \/\/ \uc751\ub2f5\uc5d0\uc11c \ud1a0\ud070 \uac12 \ucd94\ucd9c\n                var jsonResponse = await response.Content.ReadAsStringAsync();\n                var token = JsonConvert.DeserializeObject&lt;dynamic&gt;(jsonResponse).access_token;\n\n                return token;\n            }\n            else\n            {\n                Console.WriteLine(\"Error: Unable to retrieve token.\");\n                return string.Empty;\n            }\n        }\n    }\n\n    public static async Task Main(string[] args)\n    {\n        TokenService service = new TokenService();\n        string token = await service.GetNDCToken();\n\n        if (!string.IsNullOrEmpty(token))\n        {\n            Console.WriteLine(\"Access token: \" + token);\n        }\n        else\n        {\n            Console.WriteLine(\"Failed to get access token\");\n        }\n    }\n}\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Java<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:java decode:true \">import java.net.URI;\nimport java.net.http.HttpClient;\nimport java.net.http.HttpRequest;\nimport java.net.http.HttpResponse;\nimport java.net.http.HttpRequest.BodyPublishers;\nimport java.net.http.HttpResponse.BodyHandlers;\nimport java.util.Map;\nimport java.util.concurrent.CompletableFuture;\nimport java.util.stream.Collectors;\nimport com.fasterxml.jackson.databind.ObjectMapper;\n\npublic class TokenService {\n\n    private static final String TOKEN_ENDPOINT = \"https:\/\/mytoken*********.com\/test\/token\";\n    private static final String CLIENT_ID = \"your_client_id\";\n    private static final String CLIENT_SECRET = \"your_client_secret\";\n    private static final String USERNAME = \"your_username\";\n    private static final String PASSWORD = \"your_password\";\n\n    public CompletableFuture&lt;String&gt; getNDCToken() {\n        HttpClient client = HttpClient.newHttpClient();\n\n        \/\/ \ud3fc \ub370\uc774\ud130 \uc900\ube44\n        Map&lt;String, String&gt; requestData = Map.of(\n            \"grant_type\", \"password\",\n            \"username\", USERNAME,\n            \"password\", PASSWORD,\n            \"client_id\", CLIENT_ID,\n            \"client_secret\", CLIENT_SECRET,\n            \"scope\", \"openid\"\n        );\n\n        String form = requestData.entrySet()\n                .stream()\n                .map(entry -&gt; entry.getKey() + \"=\" + entry.getValue())\n                .collect(Collectors.joining(\"&amp;\"));\n\n        HttpRequest request = HttpRequest.newBuilder()\n                .uri(URI.create(TOKEN_ENDPOINT))\n                .header(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n                .POST(BodyPublishers.ofString(form))\n                .build();\n\n        \/\/ \ube44\ub3d9\uae30 POST \uc694\uccad \uc804\uc1a1\n        return client.sendAsync(request, BodyHandlers.ofString())\n                .thenApply(response -&gt; {\n                    if (response.statusCode() == 200) {\n                        try {\n                            \/\/ \uc751\ub2f5\uc5d0\uc11c \ud1a0\ud070 \ucd94\ucd9c\n                            ObjectMapper mapper = new ObjectMapper();\n                            Map&lt;String, Object&gt; jsonResponse = mapper.readValue(response.body(), Map.class);\n                            return (String) jsonResponse.get(\"access_token\");\n                        } catch (Exception e) {\n                            e.printStackTrace();\n                        }\n                    }\n                    return \"\";\n                });\n    }\n\n    public static void main(String[] args) {\n        TokenService service = new TokenService();\n        service.getNDCToken().thenAccept(token -&gt; {\n            if (!token.isEmpty()) {\n                System.out.println(\"Access token: \" + token);\n            } else {\n                System.out.println(\"Failed to get access token\");\n            }\n        });\n    }\n}\n<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>\uc124\uba85: \uc8fc\uc694 \uad6c\uc131 \uc694\uc18c: \uc774\ub7ec\ud55c \ud750\ub984\uc744 \uae30\ubc18\uc73c\ub85c \uc561\uc138\uc2a4 \ud1a0\ud070\uc774 \ubc1c\uae09\ub418\uba70, \uc774\ud6c4 \ud1a0\ud070\uc744 \uc774\uc6a9\ud574 \ubcf4\ud638\ub41c \ub9ac\uc18c\uc2a4(API)\uc5d0 \uc811\uadfc\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc694\uccad\uc5d0 \ud3ec\ud568\ub420 Data \uc608\uc2dc Response Token C# <a class=\"mh-excerpt-more\" href=\"https:\/\/www.auctionpro.co.kr\/?p=9544\" title=\"Access Token\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10],"tags":[],"class_list":["post-9544","post","type-post","status-publish","format-standard","hentry","category-devc"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/9544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9544"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/9544\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}