Generate URL Login

URL Login pada halaman Prakerja

Sebelum peserta dapat login dengan akun Prakerja, LP harus membuat URL Login di halaman Prakerja terlebih dahulu menggunakan API ini. Dengan URL yang telah didapat, LP dapat mengarahkan peserta ke URL tersebut untuk login.

Request

1curl --location 'https://api-proxy.prakerja.go.id/api/v1/oauth/authorize?state=STATE&scope=SCOPE&client_id=CLIENT_CODE&redirect_uri=CALLBACK_URI_SUCCESS&login_uri=CALLBACK_URI_FAILED' \
2--header 'X-Signature: SIGNATURE' \
3--header 'X-Timestamp: TIMESTAMP_UNIX_IN_SECONDS' \
4--header 'X-Client-Id: CLIENT_CODE'
Endpoint Path
Method
GET
Header
KeyValue
X-SignatureSignature dibuat dari raw_signature yang di-hashing menggunakan algoritma HMAC-SHA1 dengan sign_key yang disediakan Prakerja ke DP / LP
X-Timestamp

Format nilai waktu dalam satuan detik yang digunakan saat melakukan hit API

Contoh 1698289216 = 26-10-2023 10:00:16 WIB = 2023-10-26T10:00:16+07:00

X-Client-IdUnique Client ID yang disediakan Prakerja ke DP / LP.
Prakerja akan menyediakan credential yaitu kombinasi client_code dan sign_key ke DP / LP.
Query Params
FieldTypeDescription
scopestring, requiredData profile peserta yang ingin didapatkan, contoh name email prakerjaid notelp
statestring, requiredState di define oleh LP
redirect_uristring, requiredURL Callback milik LP jika login berhasil.
login_uristring, requiredURL Callback milik LP jika login gagal, umumnya ke halaman login di sisi LP.

Response

Success Response

Response 200 OK

1{
2  "message": "no error",
3  "success": true,
4  "errorCode": "0",
5  "data": {
6    "redirect_url": "GENERATED_LOGIN_URL"
7  }
8}

Response Detail

FieldTypeDescription
messagestringDeskripsi status hit API
successbooleanStatus hit API,
  • true : sukses
  • false : gagal
errorCodestringKode error di response API. Format ERRXXX
data.redirect_urlstringLP harus mengalihkan user ke redirect_url yang didapat untuk proses login.
Error Response
  • Termasuk juga list error general response
  • Response 400 Bad Request NotFoundContextClientId
    1{
    2  "code": "ERROAUTH4024",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrOauthClientIdNotFound
    1{
    2  "code": "ERROAUTH4029",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request NotFoundContextUserId
    1{
    2  "code": "ERROAUTH4030",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrOauthAuthCodeNotFound
    1{
    2  "code": "ERROAUTH4031",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrOauthAuthCodeNotSame
    1{
    2  "code": "ERROAUTH4032",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrScopeNotMatch
    1{
    2  "code": "ERROAUTH4033",
    3  "message": "scope tidak sesuai",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignatureTimestampNotInteger
    1{
    2  "code": "ERROAUTH4034",
    3  "message": "timestamp harus integer",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignatureTimestampValueGreaterThanServerNow
    1{
    2  "code": "ERROAUTH4035",
    3  "message": "timestamp melebihi waktu server",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignatureExpired
    1{
    2  "code": "ERROAUTH4036",
    3  "message": "Signature expired",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignaturePayloadInvalidJSON
    1{
    2  "code": "ERROAUTH4037",
    3  "message": "Signature payload invalid JSON",
    4  "success": false
    5}
  • Response 400 Bad Request ErrSignatureNotMatch
    1{
    2  "code": "ERROAUTH4038",
    3  "message": "Signature not match",
    4  "success": false
    5}
  • Response 400 Bad Request ErrMissingSignature
    1{
    2  "code": "ERROAUTH4039",
    3  "message": "Signature not found",
    4  "success": false
    5}
  • Response 400 Bad Request ErrMissingTimestamp
    1{
    2  "code": "ERROAUTH4040",
    3  "message": "Timestamp not found",
    4  "success": false
    5}
  • Response 400 Bad Request ErrMissingMethod
    1{
    2  "code": "ERROAUTH4041",
    3  "message": "Method not found",
    4  "success": false
    5}
  • Response 400 Bad Request ErrGrantTypeNotMatch
    1{
    2  "code": "ERROAUTH4042",
    3  "message": "grant_type tidak sesuai",
    4  "success": false
    5}
  • Response 400 Bad Request ErrRefreshTokenKeyNotFound
    1{
    2  "code": "ERROAUTH4043",
    3  "message": "Refresh token key not found",
    4  "success": false
    5}
  • Response 400 Bad Request ErrValidationInput
    1{
    2  "code": "ERROAUTH4044",
    3  "message": "Input tidak valid",
    4  "success": false
    5}
  • Response 400 Bad Request ErrRedirectUriNotValid
    1{
    2  "code": "ERROAUTH4045",
    3  "message": "Redirect URI not valid",
    4  "success": false
    5}
  • Response 400 Bad Request ErrLoginUriNotValid
    1{
    2  "code": "ERROAUTH4046",
    3  "message": "Login URI not valid",
    4  "success": false
    5}
  • Response 400 Bad Request ErrValidateJWTAuthCode
    1{
    2  "code": "ERROAUTH4047",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrValidateJWTToken
    1{
    2  "code": "ERROAUTH4048",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrCreateJWTToken
    1{
    2  "code": "ERROAUTH4049",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrJWTSignKeyNotMatch
    1{
    2  "code": "ERROAUTH4050",
    3  "message": "Unauthorized",
    4  "success": false
    5}
  • Response 400 Bad Request ErrTokenExpired
    1{
    2  "code": "ERROAUTH4051",
    3  "message": "Token expired",
    4  "success": false
    5}
  • Response 400 Bad Request ErrOauthAuthCodeExpired
    1{
    2  "code": "ERROAUTH4052",
    3  "message": "Auth code expired",
    4  "success": false
    5}
  • Response 400 Bad Request ErrTokenNotFoundHeader
    1{
    2  "code": "ERROAUTH4053",
    3  "message": "Token not found",
    4  "success": false
    5}
Try this API
 
Example Code
1// Generated by Prakerja Generator
2// for complete documentation please visit https://developer.prakerja.go.id
3
4const crypto = require('crypto-js');
5const axios = require('axios');
6
7const client_code = "";
8const sign_key = "";
9
10const timestamp = Math.round(new Date().getTime() / 1000);
11const method = "GET";
12const endpoint = "/api/v1/oauth/authorize";
13const input = client_code + timestamp + method + endpoint; // create signature input
14const signature = crypto.HmacSHA1(input, sign_key).toString(crypto.enc.Hex);
15
16const state = "";
17const scope = "name email prakerjaid userid nik notelp";
18const redirectUri = "";
19const loginUri = "";
20
21const headers = {
22  "X-Signature": signature,
23  "X-Timestamp": timestamp,
24  "X-Client-Id": client_code,
25};
26const url = 'https://api.prakerja.go.id' + endpoint + '?state=' + state + '&scope=' + scope + '&client_id=' + client_code + '&redirect_uri=' + redirectUri + '&login_uri=' + loginUri;
27
28axios({
29  method,
30  url,
31  headers,
32})
33.then((response) => {
34  console.log(response.data)
35})
36.catch((error) => {
37  console.log(error.response.data)
38});
1<?php
2// Generated by Prakerja Generator
3// for complete documentation please visit https://developer.prakerja.go.id
4
5$client_code = "";
6$sign_key = "";
7
8$timestamp = time();
9$method = "GET";
10$endpoint = "/api/v1/oauth/authorize";
11$input = $client_code . $timestamp . $method . $endpoint; // create signature input
12$signature = hash_hmac('sha1', $input, $sign_key);
13
14$state = "";
15$scope = "name email prakerjaid userid nik notelp";
16$redirectUri = "";
17$loginUri = "";
18
19$headers = [
20  "X-Signature: " . $signature,
21  "X-Timestamp: " . $timestamp,
22  "X-Client-Id: " . $client_code,
23];
24$url = 'https://api.prakerja.go.id' . $endpoint . '?state=' . urlencode($state) . '&scope=' . urlencode($scope) . '&client_id=' . $client_code . '&redirect_uri=' . urlencode($redirectUri) . '&login_uri=' . urlencode($loginUri);
25
26$ch = curl_init();
27curl_setopt($ch, CURLOPT_URL,            $url );
28curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
29curl_setopt($ch, CURLOPT_POST,           1);
30curl_setopt($ch, CURLOPT_HTTPHEADER,     $headers);
31curl_setopt($ch, CURLOPT_POSTFIELDS,     json_encode($data));
32$result = curl_exec($ch);
33curl_close ($ch);
34
35print_r("result: ");
36print_r(json_decode($result));
1# Generated by Prakerja Generator
2# for complete documentation please visit https://developer.prakerja.go.id
3
4from hashlib import sha1
5import hmac
6import time
7import json
8import requests
9
10client_code = ""
11sign_key = ""
12
13timestamp = str(int(time.time()))
14method = "GET"
15endpoint = "/api/v1/oauth/authorize"
16input = client_code + timestamp + method + endpoint
17signature = hmac.new(sign_key.encode("utf-8"), input.encode("utf-8"), sha1).hexdigest()
18
19state = ""
20scope = "name email prakerjaid userid nik notelp"
21redirectUri = ""
22loginUri = ""
23
24headers = {
25  "X-Signature": signature,
26  "X-Timestamp": timestamp,
27  "X-Client-Id": client_code,
28}
29url = 'https://api.prakerja.go.id' + endpoint + '?state=' + state + '&scope=' + scope + '&client_id=' + client_code + '&redirect_uri=' + redirectUri + '&login_uri=' + loginUri
30
31result = requests.get(
32  url,
33  headers=headers
34)
35
36print('result: ')
37print(json.loads(result.text))
1# Generated by Prakerja Generator
2# for complete documentation please visit https://developer.prakerja.go.id
3
4require 'base64'
5require 'cgi'
6require 'openssl'
7require 'net/http'
8require 'uri'
9require 'json'
10
11client_code = ""
12sign_key = ""
13
14timestamp = String(Time.now.to_i)
15method = "GET"
16endpoint = "/api/v1/oauth/authorize"
17input = client_code + timestamp + method + endpoint
18signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), sign_key.encode("ASCII"), input.encode("ASCII"))
19
20state = ""
21scope = "name email prakerjaid userid nik notelp"
22redirectUri = ""
23loginUri = ""
24
25url = 'https://api.prakerja.go.id' + endpoint + '?state=' + state + '&scope=' + scope + '&client_id=' + client_code + '&redirect_uri=' + redirectUri + '&login_uri=' + loginUri
26
27uri = URI.parse(url)
28request = Net::HTTP::Get.new(uri)
29request.content_type = "application/json"
30request['X-Signature'] = signature
31request['X-Timestamp'] = timestamp
32request['X-Client-Id'] = client_code
33
34req_options = {
35  use_ssl: uri.scheme == "https",
36}
37
38result = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
39http.request(request)
40end
41
42# result.code
43# result.body
44puts 'result: '
45puts JSON.parse(result.body)