Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Unofficial Nordigen Banking Api to retrieve account information

License

Notifications You must be signed in to change notification settings

simonhauck/unofficial-nordigen-api-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Unofficial Nordigen Banking Api to retrieve account information

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages