Git Product home page Git Product logo

unofficial-nordigen-api-java's Introduction

Unofficial Nordigen Api (Java)

Manual workflow

This project provides a generated java api for the Nordigen Banking Api which is specified here.

Modification

The api.yaml is modified to resolve some short comings.

  • Path and UUID objects were replace to strings. Some default values were invalid which lead to exceptions
  • Some methods returned void. In these cases now the raw string response is returned
  • Enums don't include a description. This lead to parsing errors with enums

Usage

  1. This project is provided via https://jitpack.io. Add the registry to your build.gradle, pom or build.gradle.kts Example build.gradle
repositories {
  ...
  maven { url 'https://jitpack.io' }
}
  1. Add the dependecy
implementation 'com.github.simonhauck:unofficial-nordigen-api-java:2.0.1' 

Basic Setup

With version 2.0 of the api the static api key was removed and users have to request now a dynamic token. The setup for this is slightly more complicated but below is an example in Kotlin and SpringBoot. I hope this gets you started :)

  1. Create two api clients, one with and one without authentication. The authentication interceptor is implemented in step 3.
@Configuration
class NordigenClientConfiguration {

    @Bean(name = ["NordigenWithAuth"])
    fun createNordigenClientWithAuth(
        @Value("\${nordigen.url}") url: String,
        nordigenApiKeyInterceptor: NordigenApiKeyInterceptor,
    ): ApiClient {
        return ApiClient().apply {
            basePath = url
            addAuthorization("NordigenToken", nordigenApiKeyInterceptor)
        }
    }

    @Bean(name = ["NordigenNoAuth"])
    fun createNordigenClientNoAuth(@Value("\${nordigen.url}") url: String): ApiClient {
        return ApiClient().apply { basePath = url }
    }
    
    // ...
 }
  1. Create you required clients. The NordigenTokenApi client does not required authentication. All other clients require the authentication
@Configuration
class NordigenClientConfiguration {
    
    @Bean
    fun createNordigenAgreementsApi(@Qualifier("NordigenWithAuth") client: ApiClient): AgreementsApi {
        return client.buildClient(AgreementsApi::class.java)
    }

    @Bean
    fun createNordigenTokenApi(@Qualifier("NordigenNoAuth") client: ApiClient): TokenApi {
        return client.buildClient(TokenApi::class.java)
    }
    
    // ...
 }
  1. Generate the code for the interceptor. Maybe its required to add the feign dependency for this explicitly in your build.gradle or pom file
@Component
class NordigenApiKeyInterceptor(
    private val nordigenTokenProvider: NordigenTokenProvider
) : RequestInterceptor {

    override fun apply(template: RequestTemplate) {
        val token = nordigenTokenProvider.getToken()
        template.header("Authorization", mutableListOf("Bearer $token"))
    }
}

@Component
class NordigenTokenProvider(
    private val nordigenTokenApi: TokenApi,

    @Value("\${nordigen.id}")
    private val nordigenSecretId: String,
    @Value("\${nordigen.key}")
    private val nordigenSecretKey: String,
) {
    fun getToken(): String {
        val body = JWTObtainPair().apply {
            secretId = nordigenSecretId
            secretKey = nordigenSecretKey
        }
        return nordigenTokenApi.jWTObtain(body).access
    }
}
  1. Profit?! Now you can access the api
@Component
class ApiExample(private val agreementsApi: AgreementsApi) {

    fun endUserAgreementRequest(institutionId: String): EndUserAgreement {
        val endUserAgreementBody = getAgreementsBody(institutionId)
        return agreementsApi.createEUAV2(endUserAgreementBody)
    }
    
    private fun getAgreementsBody(institutionIdentifier: String): EndUserAgreement {
        return EndUserAgreement().apply {
            institutionId = institutionIdentifier
            accessScope = listOf("balances", "details", "transactions")
            accessValidForDays = 10
            maxHistoricalDays = 20
        }
    }
}

For more code see the informations in the generated README

Generated code

The code for this project is generated with the OpenApi Generator. The generated code is in the generated directory.

Api Documentation

Please refer to this README

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.